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:贴个递归的。。

Posted by 306469974 at 2013-09-07 15:22:49 on Problem 1731
In Reply To:贴个递归的。。 Posted by:317358117 at 2011-02-04 18:22:57
> #include<iostream>
> #include<algorithm>
> using namespace std;
> char in[300],l[300],o[300];
> void f(int d)
> {
> 	char c='\0';
> 	if(d==strlen(in))
> 	{
> 		o[d]='\0';
> 		cout<<o<<endl;
> 	}
> 	for(int i=0;i<strlen(in);i++)
> 		if(!l[i]&&in[i]!=c)
> 		{	
> 			o[d]=in[i];
> 			l[i]=1;
> 			c=in[i];
> 			f(d+1);
> 			l[i]=0;
> 		}
> }
> int main()
> {
> 	while(cin>>in)
> 	{
> 		sort(in,in+strlen(in));
> 		memset(l,0,sizeof(l));
> 		f(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