2549 natural numbers and decomposition
time limit: 1 sspace limit: 32000 KBtitle level: Silver SolvingView Run ResultsTitle Description
Description
The natural number n is decomposed into the sum of several natural numbers, and the output scheme number.
Enter a description
Input Description
N, (1≤N≤50)
Output description
Output Description
Number of programmes
Sample input
Sample Input
5
Sample output
Sample Output
7
Data range and Tips
Data Size & Hint
5 can be divided into
1 1 1) 1 1
1 1 1 2
1 1 3
1 2 2
1 4
2 3
5
Category labels
Tags Click here to expandDepth-First Search search
#include <cstdio>#include<iostream>using namespacestd;inta[1010],n,tot;voidDfsintXintf) { for(inti=a[f-1];i<=x;i++) {//Once upon a start if(i<N) {A[f]=i; X-=i;//Split each step if(x==0){ ++tot;return; } DFS (X,f+1);//to continue splitting the split x with the next Fx+=i; } }}intMain () {scanf ("%d",&N); a[0]=1; DFS (N,1); cout<<tot+1<<endl;//Plus itself return 0;}
2549 natural numbers and decomposition