Brain a bit of a pit, do not know why, may have encountered a shadow, and now see the DFS violence search a kind of inexplicable fear, summarize the template bar
This question is still boring, direct violence search, but I write very rotten, may be this reason, looked at others template, feel good.
Learned a word "lexicography" dictionary sequence, and eat the loss of culture, WA once
#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<string>#include<stack>#include<queue>#include<algorithm>Const intINF = (1<< to)-1;Const intMAXN = -;using namespacestd;intVIST[MAXN];CharS[MAXN];//Char TS[MAXN];intTS[MAXN];intLength,n;intFlag;voidDfsintx) { if(flag)return ; if(x==5){ if(ts[0]-(int) Pow (ts[1],2)+(int) Pow (ts[2],3)-(int) Pow (ts[3],4)+(int) Pow (ts[4],5)==N) {Flag=1; //return; } return; } for(intI=0; i<length&&flag==0; i++){ if(!Vist[i]) {Vist[i]=1; TS[X]= s[i]-'A'+1; DFS (x+1); Vist[i]=0; } } return ;}intcmpintAintBB) { if(A>B)return true; Else return false;}intMain () { while(SCANF ("%d%s", &n,s), strcmp (S,"END")!=0) {flag=0; memset (Vist,0,sizeof(vist)); Length=strlen (s); Sort (s,s+length,cmp); DFS (0); if(flag) { for(intI=0;i<5; i++) {printf ("%c", ts[i]-1+'A'); } cout<<Endl; }Elseprintf ("No solution\n"); } //cout << "Hello world!" << Endl; return 0;}
View Code
hdu1015 DFS Violence search all situation templates