hdu5715 XOR Game [201,600-degree star rematch d]

Source: Internet
Author: User

The game did not think carefully, after the game is actually quite simple, the first to find out the sequence of the different or prefix and then will be different or prefix and build a trie tree, and then we can two points, the problem into a decision-making problem, to determine whether there is a scheme, so that all groups of the XOR and is greater than equal to this two- Then you can DP, using F[I][J] to indicate to J can be divided into group I, f[i][j]=f[i-1][j-k]|f[i-1][j-k+1]...| F[i-1][j-1], this thing with trie tree to maintain a bit. Single set of data Complexity O (nmlogn^2)

Code

1#include <cstdio>2 Const intN =1001010;3 intnum[n],num[n],trie[n][2],tt,sum[n];4 intN,m,l,r,i,k,j,a[n],mid;5 intflag[ One][n];6 voidAddintXinty)7 {8     inti;9      for(i=0; i<= to; i++)Tennum[i]=x&1, x>>=1; One     intt=0; A      for(i= to; i>=0; i--) -     { -         if(trie[t][num[i]]==0) trie[t][num[i]]=++tt; thet=Trie[t][num[i]]; -sum[t]+=y; -     } - } + intFindintXinty) - { +     inti; A      for(i=0; i<= to; i++) at     { -num[i]=x&1, x>>=1; -num[i]=y&1, y>>=1;  -     } -     intt=0; -      for(i= to; i>=0; i--) in     { -         if(num[i]==1) to         { +             if(!sum[trie[t][1-num[i]])return 0; -             Elset=trie[t][1-Num[i]]; the         } *         Else $         {Panax Notoginseng             if(sum[trie[t][1-num[i]])return 1; -             Else if(!sum[trie[t][num[i]])return 0; the             Elset=Trie[t][num[i]]; +         } A     } the     return 1; + } - intCheckintx) $ { $     inti,j; -      for(i=0; i<=m;i++) -      for(j=0; j<=n;j++) theflag[i][j]=0; -flag[0][0]=1;Wuyi      for(i=1; i<=m;i++) the     { -          for(j=0; j<=tt;j++) sum[j]=0; Wu          for(j=0; j<=n;j++) -         { About             if(j-k-1>=0) $             if(flag[i-1][j-k-1]) Add (a[j-k-1],-1); -flag[i][j]=find (a[j],x); -             if(flag[i-1][J]) Add (A[j],1); -         } A     } +     returnFlag[m][n]; the } - intMain () $ { the     inttest; thescanf"%d",&test); the      for(intIi=1; ii<=test;ii++) the     {  -      for(i=0; i<=tt;i++) intrie[i][0]=trie[i][1]=0; thett=0; thescanf"%d%d%d",&n,&m,&k); About      for(i=1; i<=n;i++) the     { thescanf"%d",&a[i]); thea[i]^=a[i-1]; +     } -      for(i=0; i<=n;i++) theAdd (A[i],0);BayiL=1; r=2000000000; the      while(l<=R) the     { -Mid= (l+r) >>1; -         if(Check (mid)) l=mid+1;Elser=mid-1; the     } theprintf"Case #%d:\n", ii);  theprintf"%d\n", R); the     }  -}

hdu5715 XOR Game [201,600-degree star rematch d]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.