P1025-数的划分

 1 #include <bits/stdc++.h>
 2 #define _for(i,a,b) for(int i = (a);i < b;i ++)
 3 typedef long long ll;
 4 using namespace std;
 5 int rnt = 0;
 6 int N,K;
 7 inline ll read()
 8 {
 9     ll ans = 0;
10     char ch = getchar(), last = ' ';
11     while(!isdigit(ch)) last = ch, ch = getchar();
12     while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
13     if(last == '-') ans = -ans;
14     return ans;
15 }
16 inline void write(ll x)
17 {
18     if(x < 0) x = -x, putchar('-');
19     if(x >= 10) write(x / 10);
20     putchar(x % 10 + '0');
21 }
22 
23 void dfs(int st,int le,int fi)
24 {
25     if(st==K && le>=fi)
26     {
27         rnt ++;
28         return ;
29     }
30     
31     _for(i,fi,le-(K-st)+1)
32         dfs(st+1,le-i,i);
33 }
34 int main()
35 {
36     N = read();// sum
37     K = read();// div
38     dfs(1,N,1);
39     write(rnt);
40     return 0;
41 }

 

posted @ 2019-08-01 15:18  Asurudo  阅读(121)  评论(0编辑  收藏  举报