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:next_permutation()就是好使In Reply To:next_permutation()就是好使 Posted by:Eli_love at 2010-03-31 20:53:36 #include<iostream> #include<algorithm> using namespace std; int main() { int n,k; while(scanf("%d%d",&n,&k)!=EOF){ int i,j,a[11],b1[11],b2[11]; for(i=0;i<n;i++) b1[i]=a[i]=i+1; do{ for(i=0;i<n;i++) b1[i]=a[i]; for(j=0;j<n-1;j++){ for(i=0;i<n-j-1;i++) b2[i]=b1[i]+b1[i+1]; for(i=0;i<n-j-1;i++) b1[i]=b2[i]; } if(b1[0]==k) { for(i=0;i<n-1;i++) printf("%d ",a[i]); printf("%d\n",a[n-1]); break;} next_permutation(a,a+n); }while(1); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator