Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:next_permutation()就是好使

Posted by qylsw at 2010-07-22 21:29:44 on Problem 3187
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator