HDU 4651 2013多校联合第5场 Partition 数论
来源:互联网 发布:港台网络电视直播软件 编辑:程序博客网 时间:2024/05/14 14:27
Partition
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 422 Accepted Submission(s): 242
Problem Description
How many ways can the numbers 1 to 15 be added together to make 15? The technical term for what you are asking is the "number of partition" which is often called P(n). A partition of n is a collection of positive integers (not necessarily distinct) whose sum equals n.
Now, I will give you a number n, and please tell me P(n) mod 1000000007.
Now, I will give you a number n, and please tell me P(n) mod 1000000007.
Input
The first line contains a number T(1 ≤ T ≤ 100), which is the number of the case number. The next T lines, each line contains a number n(1 ≤ n ≤ 105) you need to consider.
Output
For each n, output P(n) in a single line.
Sample Input
45111519
Sample Output
756176490
思路:此题坑了,虽然很快想出了dp 的解法确发现根本开不了如此之大的数组。方法是:dp[n][k]代表k个数加起来等于n的种数。转移方程很容易dp[n][k]=dp[n-1][k-1]+dp[n-k][k]。本题正解用的是五边形数定理:(摘wiki百科里面的一段)
考虑项的系数,在 n>0 时,等式右侧的系数均为0,比较等式二侧的系数,可得
因此可得到分割函数p(n)的递归式
其中规律是两项两项的加减变化。然后里面是n-pi,其中pi是.其他细节可以看代码。
/* * File :tmp.cpp * Author :Kevin Tan * Source :ZJNU * * 2013年8月7日,下午7:16:41 */#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<climits>#include<utility>#include<cctype>#include<iomanip>#include<string>#include<map>#include<deque>#include<queue>#include<set>#include<vector>#include<iterator>using namespace std;#define MAX 100005#define MOD 1000000007int q[MAX], p[MAX];int main(int argc, char **argv) {q[0] = 0;int k = 1;for (int i = 1; q[k - 1] <= MAX; i++) {q[k++] = (3 * i * i - i) / 2;q[k++] = (3 * i * i + i) / 2;}p[0] = 1;for (int i = 1; i <= MAX; i++) {p[i] = 0;for (int j = 1; q[j] <= i; j++) {if (((j - 1) >> 1) & 1) p[i] = (p[i] - p[i - q[j]]) % MOD;//(j-1)>>1 &1是符号两位两位的变else p[i] = (p[i] + p[i - q[j]]) % MOD;if (p[i] < 0) p[i] += MOD;}}int T;scanf("%d", &T);while (T--) {int n;scanf("%d", &n);printf("%d\n", p[n]);}return 0;}
- HDU 4651 2013多校联合第5场 Partition 数论
- HDU 4658 2013 多校联合赛第6场 Integer Partition
- hdu 4602 partition 2013多校联合训练第一场
- hdu 4651 Partition 多校第五场
- 2013 多校第五场 hdu 4651 Partition
- HDU 3521 2010多校联合第9场 数学
- hdu 4398 多校联合赛 第九场 X mod f(x) 数论
- hdu 4361 2013多校联合训练第3场最后一题
- HDU 4638 2013多校联合第4场 G-Group
- HDU 4632 2013多校联合第4场 A - Palindrome subsequence
- HDU 4655 2013多校联合赛第6场 Cut Pieces
- 2013 多校联合 C Partition (hdu 4602)
- 2013 多校第一场 hdu 4602 Partition
- hdu 4602 Partition 多校第一场
- 2013年HDU多校联合第三场解题报告
- hdu 4379 The More The Better 多校联合赛事第8场
- 2014多校联合第9场1011题||hdu 4970 树状数组
- 2014多校联合第9场1002||hdu 4691 质因子
- 关于android资源的命名规范
- 超级面试题网站
- [poj 1985]Cow Marathon[求树的直径][BFS]
- A*寻路算法实现文章(不完全翻译)
- Nginx配置文件详细说明
- HDU 4651 2013多校联合第5场 Partition 数论
- 最通俗易懂的安卓intent intent-filter
- 文件目录获取获取文件名类型demo
- Leap Moition体感器设置对话框的使用
- linux eclipse 启动错误
- 如何在jni层(HAL层)进行直接显示
- c++学习之命名空间和异常
- Java容器集合类的区别用法
- 使用向量点积来实现将模型绕着中心点旋转