| ||||||||||
| 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: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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator