2549 natural numbers and decomposition

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.