The number of divisions: the Blue Bridge

ALGO - 22. The number of divisions of

Problem Description
  The integer n into k parts, and each can not be empty, any two can have the same ( without regard to order ) .
  For example: n-=. 7, K =. 3, the three kinds of sub ⾯ method is considered to be the same.
  115; 151; 511;
  Q. How many different points system.
START input format
  nk
Output Format
  ⼀ integer, i.e., different sub-methods
Sample lose START
7 3
Sample Output
4 { four kinds of points of law: 1 , 1 , 5; 1 , 2 , 4; 1 , 3 , 3; 2 , 2 , 3;}
Data size and conventions. 6 <n-<= 200 is, 2 <= K <=. 6
Analysis: recursion, step represents the current number of remaining divided parts need ~~
The n into k parts, only the first frame number is equal to i, is calculated from i is equal to 1 until i is equal to n ⼀ / k, and the remaining k-1 ni is divided into the number of kinds of parts
⼀ number before the number of remaining front to be divided, each i from the front until the start ⼀ n / step ends, so as to ensure plan obtained
Points shutter mode is not diminishing, in order to ensure there will be no duplication of production ⽣ ~
#include <iostream>
using namespace std;
int   cnt = 0;
void  dfs( int front, int n, int step) {
      if( step == 1) {
          cnt++;
          return ;
      }
      for( int i = front; i <= n / step; i++)
           dfs(i, n - i, step - 1);
}
int main() {
    int n, k;
    cin >> n >> k;
    dfs(1, n, k);
    cout << cnt;
    return 0; 
}

 

Published 736 original articles · won praise 123 · views 80000 +

Guess you like

Origin blog.csdn.net/S_999999/article/details/103341543