HDU 4658 Integer Partition

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<=10 5
 

Output
T lines, each line contains answer to the responding test case. 
Since the numbers can be very large, you should output them modulo 10 9+7.
 

Sample Input
  
  
4 4 2 4 3 4 4 4 5
 

Sample Output
  
  
2 4 4 5

生成函数+五边形数定理+分割函数

#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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值