1299: [LLH Invitational] chocolate bar __ Game theory

Source: Internet
Author: User
Tags time limit
1299: [LLH Invitational] chocolate barTime Limit:10 Sec Memory limit:162 MB
submit:469 solved:269
[Submit] [Status] [Discuss] Description

TBL and X play games with chocolate bars. Each time a person can take a few bars out of a box, or eat a bar of chocolate out of a positive integer length. TBL Two people take turns, unable to operate the people lose. They carried out 10 rounds (one box at a time) with the best strategy. Can you predict the outcome? Input

Enter data in a total of 20 rows. 2i-1 a positive integer ni that represents the number of chocolate bars in the first round. The 2nd I line ni a positive integer li,j, indicating the length of the chocolate bar of the first round. Output

The output data consists of 10 rows. Each line outputs "YES" or "NO" to indicate whether TBL will win. If wins the output "NO", otherwise the output "YES" Sample Input 3
11 10 15
5
13 6 7 15 3
2
15 12
3
9 7 4
2
15 12
4
15 12 11 15
3
2 14 15
3
3 16 6
4
1 4 10 3
5
8 7 7 5 12
Sample Output YES
NO
YES
YES
YES
NO
YES
YES
YES
NO
HINT

20% of points, n<=5,l<=100.

40% of points, n<=7. 50% of points, l<=5,000.

100% of points, n<=14,l<=1,000,000,000.

Source

[Submit] [Status] [Discuss]
Without the chocolate bar, it would be a NIM game ... Nim who can't play. X is a hand, when tbl to take out a number of chocolate bars at random ... in Most cases, this number of root XOR and not 0, then x always allows them to operate after 0 so TBL has to get the chocolate bar .... So x can play like this derivation, obviously, to win when and only if can take out a set of chocolate bar, so that its XOR and for 0 of course, the winning strategy is to get a maximum set of its XOR and 0 of n very small, Just a violent search.

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
 
int n,a[20];
 
BOOL Dfs (int x,int sum,int tot)
{
    if (!sum && tot) return 1;
    if (x > N) return 0;
    if (DFS (x + 1,sum,tot)) return 1;
    if (DFS (x + 1,sum ^ A[x],tot + 1)) return 1;
    return 0;
}
 
int main ()
{
    #ifdef DMC
        freopen ("DMC.txt", "R", stdin);
    #endif for
     
    (int I = 1; I <= 10; i++)
    {
        scanf ("%d", &n);
        for (int i = 1; I <= n; i++) scanf ("%d", &a[i));
        Puts (Dfs (1,0,0)? "NO": "Yes");
    return 0;
}

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.