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:我的为何TLEIn Reply To:这题意思其实就是让每个字母出现偶数次,用xor优化会很快 Posted by:lydliyudong at 2011-11-01 13:41:40 #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; int a[30],ansstate; char tmp[100]; int main() { int N; scanf("%d",&N); for(int i=1;i<=N;i++) { scanf("%s",tmp); int state=0; for(int j=0;tmp[j];j++) state|=(1<<(tmp[j]-'A')); a[i]=state; } int ans=0; for(int i=1;i<(1<<N);i++) { int final=0,cnt=0; for(int j=0;j<N;j++) if(i&(1<<j)) { final^=a[j+1]; cnt++; } if(final==0) if(cnt>ans) { ans=cnt; ansstate=i; } } printf("%d\n",ans); for(int i=0;i<N;i++) if(ansstate&(1<<i)) printf("%d ",i+1); printf("\n"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator