2549 自然数和分解
时间限制: 1 s
空间限制: 32000 KB
题目等级 : 白银 Silver
传送门
题目描述 Description
把自然数N分解为若干个自然数之和,输出方案数。
输入描述 Input Description
N,(1≤n≤50)
输出描述 Output Description
方案数
样例输入 Sample Input
5
样例输出 Sample Output
7
数据范围及提示 Data Size & Hint
5
可分为
1 1 1 1 1
1 1 1 2
1 1 3
1 2 2
1 4
2 3
5
/* 又一搜索标签中的DP题. 一想到方案数就想到背包(—ˉ—) 显然j的方案数可以由j-i的方案数转移而来. 有s[j]+=s[j-i]. */ #include<iostream> #include<cstdio> #define MAXN 51 using namespace std; int s[MAXN],n; int main() { s[0]=1; cin>>n; for(int i=1;i<=n;i++) for(int j=i;j<=n;j++) s[j]+=s[j-i]; cout<<s[n]; return 0; }
来源:https://www.cnblogs.com/nancheng58/p/6070836.html