Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
晒晒我的方法回溯枚举每个位置可能的排列组合 并按字典序生成 注意最后一位不能大于k #include<iostream> using namespace std; int f[14]; int s[14]; int k; void retion(int n,int m,int l) { int i; if(!n && s[6]<=k) { for(i=1;i<6;i++) cout<<f[s[i]]<<" "; cout<<f[s[6]]<<endl; } else if(n) { for(i=m+1;i<=l/n;i++) { s[6-n+1]=i; retion(n-1,i,l-i); } } } int main() { int i; while(1) { cin>>k; if(k==0) break; for(i=1;i<=k;i++) cin>>f[i]; retion(6,0,k*(k+1)/2); cout<<endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator