首页 > 其他分享 >HDU 4651 Partition

HDU 4651 Partition

时间:2022-11-09 18:31:53浏览次数:41  
标签:HDU int Partition number base 4651 maxn line include


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.


 



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 ≤ 10 5) you need to consider.


 



Output


For each n, output P(n) in a single line.


 



Sample Input


4 5 11 15 19


 



Sample Output


490


整数划分,五边形数定理

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

void init()
{
int n = 1000;
for (int i = 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 main()
{
init();
scanf("%d", &T);
while (T--) scanf("%d", &n), printf("%d\n", p[n]);
return 0;
}



标签:HDU,int,Partition,number,base,4651,maxn,line,include
From: https://blog.51cto.com/u_15870896/5837738

相关文章

  • 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<......
  • 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大的数。思......
  • HDU-1260 Tickets
    感觉题目还是比较水的,我这个蒟蒻也能写出来hh。思路:f[i]是前i个人(包含第i个)买票需要花费的总时间,第i个人买票所需时间,可以自己单买(f[i-1]+a[i]),也可以和前面那个人拼......
  • HDU 1686Oulipo ———————Hash or KMP
    OulipoOulipoTimeLimit:3000/1000MS(Java/Others)    MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):22302    AcceptedSubmission(s):86......
  • HDU 2050折线分割平面(递推)
    折线分割平面TimeLimit:2000/1000MS(Java/Others)    MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):36479    AcceptedSubmission(s):244......
  • HDU2535Vote
     TimeLimit:5000/1000MS(Java/Others)    MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):7302    AcceptedSubmission(s):3735 Probl......
  • [题解] HDU7060 Separated Number 思路整理
    题目链接HDU7060SeparatedNumber题目大意给一个\(n\)位数,把该数字分成\(k\)段,每种方案的贡献为其分割出的段的数字之和。求所有分法的贡献之和(对\(998244353\)......
  • HDU - 2717
    大概是自己第一次在图之外用搜索吧(wwww要是早点做过的话可能蓝桥省赛的那个记忆化搜索就能a出来了hhhhttps://vjudge.net/problem/HDU-2717#author=shiyifan(这是hdu源链......