HDU 4658 2013 多校联合赛第6场 Integer Partition
2013-08-10 14:48
260 查看
Integer Partition
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 201 Accepted Submission(s): 97
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
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.
Sample Input
4 4 2 4 3 4 4 4 5
Sample Output
2 4 4 5
Source
2013 Multi-University Training Contest
6
题意 将一个整数分拆成几个整数相加,其中相同的因子不能重复出现k次,问共有多少种不同的分法。注意此处不区分数的排列位置。
思路 整数分拆的升级版,只要理解五边形数定理就不难了,直接将前一次写的代码改一下就好了。
AC代码:
/* * 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 1000000007 int q[MAX], p[MAX]; int solve(int n,int k){ int res = 0; for (int j = 0; q[j]*k <= n; j++) { if (((j + 1) >> 1) & 1) res = (res - p[n - k*q[j]]) % MOD;//此处j从0开始,j-1改成j+1 else res = (res + p[n - k*q[j]]) % MOD; if (res < 0) res += MOD; } return res; } 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; } } //for(int i=1;i<=100;i++)cout<<q[i]<<' ';cout<<endl; int T; scanf("%d", &T); while (T--) { int n,t; scanf("%d%d", &n,&t); printf("%d\n", solve(n,t)); } return 0; }
相关文章推荐
- 2013 多校第六场 hdu 4658 Integer Partition(五边形数定理,整数划分)
- HDU 4658 Integer Partition (2013多校6 1004题)
- hdu 4602 partition 2013多校联合训练第一场
- HDU 4655 2013多校联合赛第6场 Cut Pieces
- 2013 多校联合 C Partition (hdu 4602)
- HDU 4651 2013多校联合第5场 Partition 数论
- hdu 4607 park visit 2013多校联合训练第一场
- 2013多校联合4 1010 K-string (hdu 4641)
- HDU 4649 Professor Tian (2013多校联合5 1007)
- hdu 4661 Message Passing 树形dp (2013多校联合)
- 2013 多校联合 H Park Visit (hdu 4607)
- hdu 4674 边双连通缩点+倍增lca+麻烦的讨论 (2013多校联合)
- hdu 4658 Integer Partition(整数拆分变形)
- 【hdu 4658】Integer Partition (无序分拆数、五边形数定理)
- hdu 4677 并查集+分块算法 好题 (2013多校联合)
- 2013多校联合8 String (hdu 4681)
- HDU 4658 Integer Partition(整数拆分)
- 2013多校联合2 I Warm up 2(hdu 4619)
- HDU 4686 Arc of Dream (2013多校联合9 1001)
- 2013 多校联合 2 A Balls Rearrangement (hdu 4611)