SDU summer training qualifying (1) solution to a problem

E - Everyone wants Khaleesi

Consider A step ahead to reach the point x, first of all win if the point x, x is a condition to win the point is: if x is not n, then the point x degrees must have two points to win, otherwise B will be able to cut He points out the path to victory. n point is to win points, pushing forward from the point n, you will find all the points are doomed to failure point, because it is a dag. So unless A possible step to reach the point n, or A doomed to failure.

 

F - Flipping Rectangles

R1 and r2 move to consider the number of steps required to pay the local area, and k size comparison, the next step is to enumerate the up and down direction, moving one step left and right direction.

G - Gift Pack

Digital $ dp $. This question is easier to think greedy, say I was in the race, would like greedy beginning to take from a high level, but it is easy to find, if enumerate the bits $ 8 $ case, not only produce $ 0 $ or $ 1 $, it may also have $ 2 $, that is to say, will produce a carry, so greed is not right. The correct approach is that we can digital $ dp $, by $ dp [i] [al] [ar] [b] [c] $ shows a case where the most significant bit to bit i posted boundary is $ (al, ar , b, c) when the maximum $ answer, where $ (al, ar, b, c) $, respectively, the first number refers to whether the lower bound paste, paste whether the first sector number, whether the number of the second sector paste and whether the number of labeled third sector, the transfers are $ 8 $ enumerate the case as long as bit, whether cross-border under judgment, taking all circumstances maximum can be.

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 typedef long long ll;
 5 typedef std::pair<ll,ll> P;
 6 ll dp[66][2][2][2][2];
 7 ll L,R,A,B;
 8 ll dfs(int pos,bool al,bool ar,bool b,bool c) {
 9     if(pos<0) return 0;
10     if(dp[pos][al][ar][b][c]!=-1) return dp[pos][al][ar][b][c];
11     int aL=0,aR=1,upb=1,upc=1;
12     if(al) aL=L>>pos&1;
13     if(ar) aR=R>>pos&1;
14     if(b) upb=A>>pos&1;
15     if(c) upc=B>>pos&1;
16     ll &ans=dp[pos][al][ar][b][c];
17     for(int i=0;i<8;i++) {
18         int na,nb,nc;
19         na=i&1;
20         nb=i>>1&1;
21         nc=i>>2&1;
22         if(na<aL||na>aR) continue;
23         if(nb>upb) continue;
24         if(nc>upc) continue;
25         ll tmp=(na^nb)+(na^nc)+(nb&nc);
26         tmp<<=pos;
27         ans=std::max(ans,tmp+dfs(pos-1,al&&na==aL,ar&&na==aR,b&&nb==upb,c&&nc==upc));
28     }
29     return ans;
30 }
31 int main() {
32     int n;
33     //printf("%lld\n",1LL<<61);
34     scanf("%d",&n);
35     while(n--) {
36         scanf("%lld%lld%lld%lld",&L,&R,&A,&B);
37         memset(dp,-1,sizeof(dp));
38         printf("%lld\n",dfs(61,1,1,1,1));
39     }
40     return 0;
41 }
View Code

 

Guess you like

Origin www.cnblogs.com/Onlymyheart/p/11233547.html