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:我的为何TLE

Posted by sjynoi at 2011-12-21 17:44:13 on Problem 1903
In 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:
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