当前位置:网站首页>整数划分
整数划分
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;
}
边栏推荐
- Children's unit of 2022 Paris fashion week ended successfully at Wuhan station on June 19
- Unity - use of API related to Pico development input system ---c
- Study notes 22/1/17
- Oracle view all tablespaces in the current library
- The preliminary round of the sixth season of 2022 perfect children's model Foshan competition area came to a successful conclusion
- Set the encoding of CMD to UTF-8
- 安装nrm后,使用nrm命令报错internal/validators.js:124 throw new ERR_INVALID_ARG_TYPE(name, ‘string‘, value)
- 券商注册开户靠谱吗?安全吗?
- Upgrade HDP spark to spark 2.4.8 without upgrading ambari
- nlp序列完全可以模拟人脑智能
猜你喜欢

【js】-【DFS、BFS应用】-学习笔记

SQL master-slave replication setup

Eslint syntax monitoring off

SQL analysis (query interception analysis for SQL optimization)

B_ QuRT_ User_ Guide(28)

PLSQL installation under Windows

Today's notes 22/1/7

MySQL tablespace parsing

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

匿名页的反向映射
随机推荐
Usage record of Xintang nuc980: self made development board (based on nuc980dk61yc)
PLSQL installation under Windows
Eslint syntax monitoring off
ROS 笔记(08)— 服务数据的定义与使用
解决npm ERR! Unexpected end of JSON input while parsing near问题
Connaissez - vous le protocole TCP (2)?
Prometheus deployment alarm docking QQ mailbox
Configuring MySQL multi instance master-slave synchronization for Linux
Study notes 22/1/17
Installing MySQL under Linux
Airflow2.x distributed deployment DAG execution failure log cannot be obtained normally
图像翻译:UVCGAN: UNET VISION TRANSFORMER CYCLE-CONSISTENT GAN FOR UNPAIRED IMAGE-TO-IMAGE TRANSLATION
asp. Net datalist to display product information and pictures
ROS notes (09) - query and setting of parameters
Why MySQL cannot insert Chinese data in CMD
【学习笔记】搜索
Ambari (V) ---ambari integrated Azkaban (valid for personal test)
Solve NPM err! Unexpected end of JSON input while parsing near
B_QuRT_User_Guide(30)
Jenkins' common build trigger and hook services (V)