标签:
Let us consider sets of positive integers less than or equal to n. Note that all elements of a set are different. Also note that the order of elements doesnt matter, that is, both {3, 5, 9} and {5, 9, 3} mean the same set.
1 #include<iostream> 2 using namespace std; 3 int a[3]; 4 int A[22]; 5 int ans=0; 6 void dfs(int n,int cur){ 7 if(cur==a[1]){ 8 int sum=0; 9 for(int i=0;i<a[1];i++){ 10 sum+=A[i]; 11 } 12 if(sum==a[2])ans++; 13 } 14 int s=1; 15 if(cur!=0)s=A[cur-1]+1; 16 for(int i=s;i<=n;i++){ 17 A[cur]=i; 18 dfs(n,cur+1); 19 } 20 } 21 int main(){ 22 while(cin>>a[0]>>a[1]>>a[2]&&a[0]+a[1]+a[2]){ 23 ans=0; 24 dfs(a[0],0); 25 cout<<ans<<endl; 26 } 27 return 0; 28 }
标签:
原文地址:http://www.cnblogs.com/demodemo/p/4696617.html