Integer Partition

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 22    Accepted Submission(s): 15

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
 
Recommend
zhuyuanchen520
 
 
 
跟上次多校求数的划分很类似。
 
 
所谓的五边形数定理还没有搞懂。
 
 
先贴个代码先,胡搞弄过去的
 
 
 /*
* Author: kuangbin
* Created Time: 2013/8/8 11:53:35
* File Name: 1004.cpp
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <time.h>
using namespace std;
const int MOD = 1e9+;
int dp[];
void init()
{
memset(dp,,sizeof(dp));
dp[] = ;
for(int i = ;i <= ;i++)
{
for(int j = , r = ; i - ( * j * j - j) / >= ; j++, r *= -)
{
dp[i] += dp[i -( * j * j - j) / ] * r;
dp[i] %= MOD;
dp[i] = (dp[i]+MOD)%MOD;
if( i - ( * j * j + j) / >= )
{
dp[i] += dp[i - ( * j * j + j) / ] * r;
dp[i] %= MOD;
dp[i] = (dp[i]+MOD)%MOD;
} } }
} int solve(int n,int k)
{
int ans = dp[n];
for(int j = , r = -; n - k*( * j * j - j) / >= ; j++, r *= -)
{
ans += dp[n -k*( * j * j - j) / ] * r;
ans %= MOD;
ans = (ans+MOD)%MOD;
if( n - k*( * j * j + j) / >= )
{
ans += dp[n - k*( * j * j + j) / ] * r;
ans %= MOD;
ans = (ans+MOD)%MOD;
} }
return ans;
} int main()
{
init();
int T;
int n,k;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&k);
printf("%d\n",solve(n,k));
}
return ;
}
 
 
 
 
 
 

最新文章

  1. 【Sorting Collection】
  2. htmlFormat
  3. Xcode7 Cocoapods 安装或更新出现错误
  4. bzoj1977 [BeiJing2010组队]次小生成树 Tree
  5. js、jquery对于html内容的转义
  6. leetcde37. Sudoku Solver
  7. Navi.Soft30.产品.阅读导航
  8. HDU4686 Arc of Dream 矩阵快速幂
  9. (三)Struts2 拦截器
  10. ASP.NET中Cookie的使用
  11. crf 分词(待)
  12. utf8+bom格式保存php curl乱码问题
  13. STM32中断优先级理解
  14. 【经验】AngularJS
  15. 解决Win10系统本地主机,网络受限占用CPU过高的问题
  16. 截止2017年,最新的全国行政区划代码数据源(xml)
  17. Linux 源码安装 Python3
  18. Java基础复习笔记基本排序算法
  19. LeetCode - Rotate String
  20. tomcat8 进入不了Manager App 界面 403 Access Denied

热门文章

  1. MACACA===gradle下载和安装
  2. c++ ui 库
  3. 算法题之找出数组里第K大的数
  4. VPS性能测试(2):内存大小、交换空间、高速缓存、实际使用内存
  5. tcpcopy 流量复制
  6. linux命令(45):diff命令
  7. eclipse out of memory
  8. tk界面版股票下载
  9. OpenCL学习笔记(二):并行编程概念理解
  10. Sqrt(x)——二分法,防越界