UVALive 6661 Equal Sum Sets
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <string> 7 #include <vector> 8 #include <map> 9 #include <set> 10 #include <time.h> 11 #include <queue> 12 #include <stack> 13 #include <cctype> 14 #include <utility> 15 #include <numeric> 16 #include <cstdlib> 17 #include <functional> 18 #include <iomanip> 19 #include <sstream> 20 using namespace std; 21 int n,k,s; 22 int ans; 23 void gao(int now,int deep,int sum) 24 { 25 if(deep==k&&sum==s) {ans++;return ;} 26 if(deep>k||sum>s) return ; 27 else 28 for(int i=now+1;i<=n;i++) 29 gao(i,deep+1,sum+i); 30 return ; 31 } 32 int main() 33 { 34 35 while(scanf("%d%d%d",&n,&k,&s)!=EOF) 36 { 37 if(n+k+s==0) break; 38 ans=0; 39 for(int i=1;i<=n;i++) 40 gao(i,1,i); 41 printf("%d\n",ans); 42 } 43 return 0; 44 }