Topic description
Given the number of N, two people take turns to fetch the number, and before the number of two people or up, who can't take the number or who gets the number and before the number or value of 511 who loses, ask who can win?
Exercises
The first idea is to search directly, but need to record the status of the values taken, 2^50 obviously timed out ... For the current or value cur, or the previous number num, there are only two cases, either cur|num==cur,
For this number, just put this state directly to the next player, play the role of delaying one step, their selection order on the situation has no effect, you can take all the rotation, if the number is greater than the current number of numbers, then we can choose this number, if you choose this number can lead to the next situation will be defeated, Then the current situation will win. The second case is that Cur|num!=cur,num must have never been taken, and if there is a number num that will defeat the next situation, then the current situation is winning. If the next situation to win, then the current situation is a must lose, we can use the memory of the search to achieve the above process ~ ~ ~
Code:
1vector<int>Card;2 intdp[ -][555], N;3 intDfsintThintmask)4 {5 if(Mask = =511)return 1;6 if(th = = N)return 0;7 if(~dp[th][mask])returnDp[th][mask];8 intCNT =0;9 for(inti =0; I < n; i++)if((Card[i] | mask) = = mask) cnt++;Ten if(cnt > th &&!dfs (th +1, mask))returnDp[th][mask] =1; One for(inti =0; I < n; i++)if((Card[i] | mask)! =mask) A { - if(!dfs (th +1, Mask | Card[i]))returnDp[th][mask] =1; - } the return 0; - } - classFivehundredeleven - { + Public: - stringThewinner (Vector <int>cards) + { ACard =cards; atn =card.size (); -Memset (DP,-1,sizeof(DP)); - returnDfs0,0) ?"Fox Ciel":"Toastman"; - } -};
SRM 511 DIV1 500pt (DP)