SRM 511 DIV1 500pt (DP)

Source: Internet
Author: User

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)

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.