2549 自然数和分解

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

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<string>
 4 #include<cstring>
 5 #include<cmath>
 6 #include<algorithm>
 7 using namespace std;
 8 int a[10000]={1};
 9 int search(int,int);
10 int n;
11 int tot=0;
12 int main()
13 {
14     cin>>n;
15     search(n,1);
16     cout<<tot;
17     return 0;
18 }
19 int search(int x,int y)
20 {
21     int i;
22     for(i=a[y-1];i<=x;i++)
23      {
24               a[y]=i;
25               x-=i;
26               if(x==0)tot++;
27               else search(x,y+1);
28               x+=i;
29      }
30 }
原文地址:https://www.cnblogs.com/lyqlyq/p/6612296.html