当前位置:网站首页>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;
}
边栏推荐
- Infinite penetration test
- Understanding of CUDA, cudnn and tensorrt
- Super Jumping! Jumping! Jumping!
- After installing NRM, the internal/validators js:124 throw new ERR_ INVALID_ ARG_ TYPE(name, ‘string‘, value)
- 罗氏线圈可以测量的大电流和频率范围
- Superimposed ladder diagram and line diagram and merged line diagram and needle diagram
- Dell r730 server startup error: [xxx] USB 1-1-port4: disabled by hub (EMI?), re-enabling...
- Redis02 -- an operation command of five data types for ending redis (it can be learned, reviewed, interviewed and collected for backup)
- 关于如何在placeholder中使用字体图标
- Oracle view all tablespaces in the current library
猜你喜欢
![DELL R730服务器开机报错:[XXX] usb 1-1-port4: disabled by hub (EMI?), re-enabling...](/img/90/425965ca4b3df3656ce2a5f4230c4b.jpg)
DELL R730服务器开机报错:[XXX] usb 1-1-port4: disabled by hub (EMI?), re-enabling...

Reverse mapping of anonymous pages

Introduction, compilation, installation and deployment of Doris learning notes

隐私计算FATE-----离线预测

App automated testing appium tutorial 2 - ADB command

Usage record of Xintang nuc980: self made development board (based on nuc980dk61yc)

js取整的小技巧
![[learning notes] matroid](/img/e3/4e003f5d89752306ea901c70230deb.png)
[learning notes] matroid

The preliminary round of the sixth season of 2022 perfect children's model Foshan competition area came to a successful conclusion

匿名页的反向映射
随机推荐
抗洪救灾,共克时艰,城联优品捐赠10万元爱心物资驰援英德
Selenium reptile
隐私计算FATE-----离线预测
【.NET6】gRPC服务端和客户端开发案例,以及minimal API服务、gRPC服务和传统webapi服务的访问效率大对决
匿名页的反向映射
[learning notes] matroid
How do people over 40 allocate annuity insurance? Which product is more suitable?
广州:金融新活水 文企新机遇
罗氏线圈可以测量的大电流和频率范围
Super Jumping! Jumping! Jumping!
关于如何在placeholder中使用字体图标
B_QuRT_User_Guide(30)
Sword finger offer 03 Duplicate number in array
【力扣10天SQL入门】Day5+6 合并表
NPM clean cache
Oracle RAC -- understanding of VIP
Not so Mobile
B_QuRT_User_Guide(28)
第六届智能家居亚洲峰会暨精品展(Smart Home Asia 2022)将于10月在沪召开
The maximum number of Rac open file descriptors, and the processing of hard check failure