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 |
Re:晒晒我的方法In Reply To:晒晒我的方法 Posted by:Snow_storm at 2010-02-20 16:06:21 > 回溯枚举每个位置可能的排列组合 > 并按字典序生成 注意最后一位不能大于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