2009年12月8日 星期二

TIOJ 1094 C.幼稚國王的獎賞 [DP...?]

poao899    5124K    4656MS    G++     0.45K     2009-12-08 23:34:40                      .

過是過了但是這速度...


算了(?


暴力用背包(汗


//****************************

#include<stdio.h>
bool can[1048576];
int last[1048576];
int n,x,max;
void set(int x,int i){
if(!can[x]){
can[x]=1;
last[x]=i;
}
}
main(){
while(scanf("%d",&n),n){
for(int i=0;i<1048576;i++)
can[i] = last[i] = 0;
set(0,max=0);
for(int i=1;i<=n;i++){
scanf("%d",&x);
for(int j=0;j<1048576;j++)
if(can[j] && last[j]!=i){
set(j^x,i);
if((j^x)>max)
max=(j^x);
}
}
printf("%d\n",max);
}
}


沒有留言:

張貼留言