当前位置:网站首页>整数划分
整数划分
2022-06-28 08:10:00 【Angeliaaa】
将N分为若干个不同整数的和,有多少种不同的划分方式,例如:n = 6,{6} {1,5} {2,4} {1,2,3},共4种。由于数据较大,输出Mod 10^9 + 7的结果即可。
Input
输入1个数N(1 <= N <= 50000)。
Output
输出划分的数量Mod 10^9 + 7。
Sample Input
6Sample Output
4题意:给出一个数n,求n能被分成几个集合,使每个集合内的数相加的和等于n。
思路:这个题用dp做,dp【i】【j】表示将i分为j个数相加。当 i 等于9,j 等于3时,dp【i-j】【j】即dp【6】【3】等于1,因为6能被分为1,2,3一种,dp【i-j】【j-1】即dp【6】【2】可分为(1,5)和(2,4)两种而dp【9】【3】恰好等于3,所有dp【i】【j】=dp【i-j】【j】+dp【i-j】【j-1】.状态转移方程写出后还要知道数字n最多可分为sart(2*n)位相加。然后for循环逐一加上即可,代码如下:
#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;
}
边栏推荐
- B_QuRT_User_Guide(28)
- 三角变换公式
- redis02——一篇终结redis的五种数据类型操作命令(可学习、复习、面试、收藏备用)
- MySQL single table access method
- 【学习笔记】搜索
- Prometheus deployment alarm docking QQ mailbox
- Is it reliable to open an account by digging money? Is it safe?
- The maximum number of Rac open file descriptors, and the processing of hard check failure
- Introduction to Devops Basics
- Solve NPM err! Unexpected end of JSON input while parsing near
猜你喜欢

AI首席架构师8-AICA-高翔 《深入理解和实践飞桨2.0》

Little artist huangxinyang was invited to participate in the Wuhan station of children's unit of Paris Fashion Week

Prometheus service discovery

Image translation /transformer:ittr: unpaired image to image translation with transformers

Eslint syntax monitoring off

Ambari (V) ---ambari integrated Azkaban (valid for personal test)

Set the encoding of CMD to UTF-8

Jenkins' common build trigger and hook services (V)

App automated testing appium Tutorial Part 1 - advanced supplementary content

【尚品汇】项目笔记
随机推荐
NPM clean cache
Uvcgan: unt vision transformer cycle-consistent Gan for unpropared image-to-image translation
【js】-【节流、防抖函数】
B_ QuRT_ User_ Guide(30)
sql分析(查询截取分析做sql优化)
npm清理缓存
Prometheus monitoring (I)
[shangpinhui] project notes
关于在cmd中MySQL不能插中文数据的原因
Airflow2.x distributed deployment DAG execution failure log cannot be obtained normally
js取整的小技巧
Reverse mapping of anonymous pages
Soft test -- software designer -- database design of afternoon questions
Resolution of Rac grid failure to start after server restart
Software testing and quality final review
Is it reliable to open an account by digging money? Is it safe?
B_QuRT_User_Guide(29)
Buffer pool in MySQL
【学习笔记】搜索
【尚品汇】项目笔记