HDU5715 XOR Game Two points + dictionary tree +DP

Source: Internet
Author: User
Tags cas

At that time Astar the time to make only 1 questions, after the game (after a long time to fill, lazy really deadly), found that this is the second simple

Analysis:

This problem can be the minimum XOR of each interval and

When the check is checked, the DP is used to judge, Dp[i][j] represents the first I element into J interval, j is the last element of the last interval

If DP[I][J] is true, indicates that each interval is longer than L, XOR, or greater than mid

Otherwise it is false

Return to Dp[n][m] just fine.

Degree of Complexity O (30^2*NM)

Spit Groove: And the different or related topics are always and the dictionary tree greedy, but also together, remember

#include <stdio.h>#include<algorithm>#include<string.h>using namespacestd;Const intN = 1e4+5; typedefLong LongLL;intN,m,l,t,cas,tot;intA[n];structnode{intsum,nex[2];} P[n* ** A];intNewNode () {++tot; P[tot].sum=0;p [tot].nex[0]=p[tot].nex[1]=-1; returntot;}introot[ A];voidAddintPosintx) {  intnow=root[pos],cur; ++p[now].sum;  for(intI= -; i>=0;--i) {    if(x& (1<<i)) cur=1; ElseCur=0; if(p[now].nex[cur]==-1) P[now].nex[cur]=NewNode (); now=P[now].nex[cur]; ++p[now].sum; }}voidDelintPosintx) {  intnow=root[pos],cur; --p[now].sum;  for(intI= -; i>=0;--i) {     if(x& (1<<i)) cur=1; ElseCur=0; now=P[now].nex[cur]; --p[now].sum; }}intQueryintPosintx) {  intnow=root[pos],ret=0, cur; if(p[now].sum==0)return 0;  for(intI= -; i>=0;--i) {     if(x& (1<<i)) cur=1; ElseCur=0; if(p[now].nex[cur^1]!=-1&&p[p[now].nex[cur^1]].sum!=0) {ret+=(1<<i); now=p[now].nex[cur^1]; }     Elsenow=P[now].nex[cur]; }  returnret;}BOOLdp[n][ A];BOOLCheckintmid) {Tot=0;  for(intI=0; i<m;++i) root[i]=NewNode ();  for(intI=0; i<=n;++i) for(intj=0; j<=m;++j) dp[i][j]=false; dp[0][0]=true; Add (0,0);  for(intI=1; i<=n;++i) {    if(i-l-1>=0){       for(intj=0; j<=m;++j)if(dp[i-l-1][J]) del (j,a[i-l-1]); }     for(intj=1; j<=m;++j) {      intTmp=query (J-1, A[i]); if(tmp>=mid) Add (J,a[i]), dp[i][j]=true; }     }  returndp[n][m];}intMain () {scanf ("%d",&T);  while(t--) {scanf ("%d%d%d",&n,&m,&l);  for(intI=1; i<=n;++i) scanf ("%d", &a[i]), a[i]^=a[i-1]; intL=0, r=1e9+7, ret;  while(l<=R) {      intMid= (l+r) >>1; if(Check (mid)) l=mid+1, ret=mid; Elser=mid-1; } printf ("Case #%d:\n%d\n",++Cas,ret); }  return 0;}
View Code

HDU5715 XOR Game Two points + dictionary tree +DP

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.