HDU 4658 Integer Partition
来源:互联网 发布:数控编程人员工资待遇 编辑:程序博客网 时间:2024/05/02 00:48
Problem Description
Given n, k, calculate the number of different (unordered) partitions of n such that no part is repeated k or more times.
Input
First line, number of test cases, T.
Following are T lines. Each line contains two numbers, n and k.
1<=n,k,T<=105
Following are T lines. Each line contains two numbers, n and k.
1<=n,k,T<=105
Output
T lines, each line contains answer to the responding test case.
Since the numbers can be very large, you should output them modulo 109+7.
Since the numbers can be very large, you should output them modulo 109+7.
Sample Input
44 24 34 44 5
Sample Output
2445生成函数+五边形数定理+分割函数
#include<iostream>#include<cmath>#include<map>#include<vector>#include<queue>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn = 200005;const int base = 1000000007;int f[maxn], p[maxn], n, T, k;void init(){int n = 1000;for (int i = f[0] = 1; i <= n; i++){f[i + i - 1] = (i * (i + i + i - 1) >> 1) % base;f[i + i] = (i * (i + i + i + 1) >> 1) % base;}for (int i = p[0] = 1; i < maxn; i++){p[i] = 0;for (int j = 1, k = -1; i >= f[j]; j++){if (j & 1) k *= -1;(p[i] += k * p[i - f[j]]) %= base;}p[i] = (p[i] + base) % base;}}int work(int n, int k){int ans = p[n];for (int i = 1, j = 1; f[i] * k <= n; i++){if (i & 1) j *= -1;(ans += j * p[n - f[i] * k]) %= base;}return (ans + base) % base;}int main(){init();scanf("%d", &T);while (T--) scanf("%d%d", &n, &k), printf("%d\n", work(n, k));return 0;}
0 0
- HDU 4658 Integer Partition
- hdu 4658Integer Partition
- hdu 4658 Integer Partition
- HDU 4658 Integer Partition
- HDU-4658-Integer Partition
- hdu 4658 Integer Partition(整数拆分变形)
- hdu 4658 Integer Partition(公式)
- hdu 4658 Integer Partition 整数划分+生成函数
- 【HDU】4658 Integer Partition【生成函数——数拆分】
- Integer Partition
- HDU 4658 2013 多校联合赛第6场 Integer Partition
- 2013 多校第六场 hdu 4658 Integer Partition(五边形数定理,整数划分)
- 1113. Integer Set Partition
- Integer Set Partition
- 1113. Integer Set Partition
- A1113. Integer Set Partition (25)
- PAT--1113. Integer Set Partition
- 1113. Integer Set Partition (25)
- 从零开始打造一个新闻订阅APP之爬虫篇(二、实现一个简单的爬虫系统)
- java多线程问题中死锁的一个实现
- java web 简析--学习计划
- backbone.js练习
- LeetCode 38 Count and Say(C,C++,Java,Python)
- HDU 4658 Integer Partition
- JSOI 2008 星球大战
- 黑马程序员——1,JAVA基础:认识JAVA
- iOS中的MVC设计模式
- ACM小组的古怪象棋
- Linux下Pomelo环境配置
- 教女友学PHP之HTML①
- ConcurrentHashMap原理解析
- 教女友学PHP之HTML②