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 |
这题意思其实就是让每个字母出现偶数次,用xor优化会很快题目是让找最多的骨骼,使得每个字母都出现偶数次。 第i个字母,就用i个1(二进制下)代替,预处理出每个骨骼上的字母xor后的值。 然后2^N爆搜,最后xor值为0的就是一个可行解。 var a,b,c,d:array[0..26]of longint; s:ansistring; n,i,j:longint; procedure dfs(x,y,temp:longint); begin if x=n+1 then begin if (temp=0)and(c[0]>d[0]) then d:=c; exit; end; dfs(x+1,y,temp); inc(c[0]); c[c[0]]:=x; dfs(x+1,y+1,temp xor b[x]); dec(c[0]); end; begin for i:=1 to 26 do a[i]:=1<<i-1; readln(n); for i:=1 to n do begin readln(s); for j:=1 to length(s) do b[i]:=b[i] xor a[ord(s[j])-64]; end; dfs(1,0,0); writeln(d[0]); for i:=1 to d[0] do write(d[i],' '); writeln; end. Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator