当前位置:网站首页>Integer partition
Integer partition
2022-06-28 08:31:00 【Angeliaaa】
take N The sum of several different integers , How many different ways are there , for example :n = 6,{6} {1,5} {2,4} {1,2,3}, common 4 Kind of . Because of the big data , Output Mod 10^9 + 7 As a result of .
Input
Input 1 Number N(1 <= N <= 50000).
Output
Output the number of partitions Mod 10^9 + 7.
Sample Input
6Sample Output
4The question : Give a number n, seek n Can be divided into several sets , Make the sum of the numbers in each set equal to n.
Ideas : This question is in Chinese dp do ,dp【i】【j】 It means that you will i It is divided into j Add up the numbers . When i be equal to 9,j be equal to 3 when ,dp【i-j】【j】 namely dp【6】【3】 be equal to 1, because 6 Can be divided into 1,2,3 A kind of ,dp【i-j】【j-1】 namely dp【6】【2】 Can be divided into (1,5) and (2,4) Two and dp【9】【3】 Exactly equal to 3, all dp【i】【j】=dp【i-j】【j】+dp【i-j】【j-1】. After the state transition equation is written, you need to know the numbers n It can be divided into sart(2*n) Add bits . then for Add one cycle after another , The code is as follows :
#include<stdio.h>
#include<math.h>
int a[50010][350];
int main()
{
int n,i,j,k;
while(~scanf("%d",&n))
{
a[0][0]=1;
int sum=0;
k=sqrt(2*n);
for(i=1;i<=n;i++)
{
for(j=1;j<=k;j++)
{
if(i>=j)
a[i][j]=(a[i-j][j]+a[i-j][j-1])%1000000007;
}
}
for(i=1;i<=k;i++)
sum=(sum+a[n][i])%1000000007;
printf("%d\n",sum);
}
return 0;
}
边栏推荐
- About ASM disk space full, clean up ASM disk
- The maximum number of Rac open file descriptors, and the processing of hard check failure
- Cloudcompare & PCL point cloud clipping (based on closed surfaces or polygons)
- Almost Union-Find(带权并查集)
- NPM clean cache
- 块级元素上下左右居中的两个小技巧
- The 6th smart home Asia 2022 will be held in Shanghai in October
- B_QuRT_User_Guide(28)
- Installing mysql5.7 under Windows
- Discussion on the application of GIS 3D system in mining industry
猜你喜欢
随机推荐
[go ~ 0 to 1] on the first day, June 24, variables, conditional judgment cycle statement
Case tool
【学习笔记】线性基
Not so Mobile
A - Bi-shoe and Phi-shoe
2022第六季完美童模 佛山赛区 初赛圆满落幕
Oracle view tablespace usage
匿名页的反向映射
How to choose an account opening broker? Is it safe to open an account online?
Why are function templates not partial specialization?
B_QuRT_User_Guide(26)
Love analysis released the 2022 love analysis · it operation and maintenance manufacturer panorama report, and an Chao cloud was strongly selected!
[learning notes] matroid
887. egg drop
AI chief architect 8-aica-gao Xiang, in-depth understanding and practice of propeller 2.0
B_ QuRT_ User_ Guide(30)
【学习笔记】最短路 +生成树
PC端隐藏滚动条
开户券商怎么选择?网上开户是否安全么?
Goldbach`s Conjecture









