首页 > 其他分享 >HDU 4658 Integer Partition

HDU 4658 Integer Partition

时间:2022-11-09 18:32:46浏览次数:41  
标签:HDU int Partition base maxn ans Integer line include


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;
}



标签:HDU,int,Partition,base,maxn,ans,Integer,line,include
From: https://blog.51cto.com/u_15870896/5837734

相关文章

  • HDU 5638 Toposort
    ProblemDescriptionn verticesand m edges.Youareallowedtodeleteexact k InputT indicatingthenumberoftestcases.Fore......
  • HDU 4651 Partition
    ProblemDescriptionHowmanywayscanthenumbers1to15beaddedtogethertomake15?Thetechnicaltermforwhatyouareaskingisthe"numberofpart......
  • BigInteger,BigDecimal
    BigInteger方法名说明publicBigInteger(intnum,Randomrnd)获取随机大整数,范围:[0~2的num次方-1]publicBigInteger(Stringval)获取指定的大整数......
  • Least Number of Unique Integers after K Removals
    https://leetcode.cn/problems/least-number-of-unique-integers-after-k-removals/ #https://leetcode.com/problems/least-number-of-unique-integers-after-k-remo......
  • 【javaweb】integer是什么意思?integer和int的区别
    1、数据类型不同:int是基础数据类型,而integer是包装数据类型2、默认值不同:int的默认值是0,而integer的默认值是null3、内存中存储的方式不同:int在内存中直接存储的是数据......
  • oracle partition by与group by 的区别
    SELECTb,c,d,SUM(d)OVER(PARTITIONBYb,cORDERBYd)eFROMa  今天看到一个老兄的问题,大概如下:查询出部门的最低工......
  • Palindrome Partitioning II
    https://leetcode.cn/problems/palindrome-partitioning-ii/dp[i]表示s[0..i]切分为回文子串的最小分割次数dp[i]=min(dp[j]+1),如果s[j+1...i]是回文串,j<......
  • CASE types integer and text cannot be matched
    报以上错误可能的错误场景之一是:当你在写casewhen语句的时候,when不同的条件的时候then里面想拼接内容,使用了concat()函数注:请认真阅读,出现这种错误说明你对case......
  • HDU 1028
    如果只有\(1\)数字,多项式为:\(1+x+x^2+x^3+\ldots\)。如果只有\(2\)数字,多项式为:\(1+x^2+x^4+x^6+\ldots\)。……如果只有\(k\)数字,多项式为:\(1+x^k+x^{2k}+x^{3......
  • B - K-th Number HDU - 6231 (二分 尺取)
    WindowsSource2017中国大学生程序设计竞赛-哈尔滨站题意给一个数组,在所有长度大于等于k的区间内,找出第\(k\)大的数,放到另一个数组中,然后在新数组中找到第M大的数。思......