The number of divisions - the search base

The integer n into k parts, and each can not be empty, any two schemes are different (regardless of order).

For example: n-=. 7 , K =. 3 , the following three sub-methods are considered the same.

1,1,5
1,5,1
5,1,1;

Q. How many different points system.

 

Sample input and output

Input Sample # 1: Copy
7 3
Output Sample # 1: Copy
4
#include<iostream>
#include<algorithm>
using namespace std;
int n, k, cnt;
void dfs(int u, int sum, int cur){
    if(cur==k){
        if(sum==n)cnt++;
        return ;
    }
    for(int i=u;sum+i*(k-cur)<=n;i++)
        dfs(i,sum+i,cur+1);
}
int main(void){
    cin>>n>>k;
    dfs(1,0,0);
    cout<<cnt<<endl;
}

 

Guess you like

Origin www.cnblogs.com/programyang/p/11232266.html