UVa 10404 Bachet ' s Game (dp& game)

Source: Internet
Author: User
Tags bool time limit

10404-bachet ' s Game

Time limit:6.666 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_ problem&problem=1345

Game ~

Rule 1: A state is a must-lose state if and only if all subsequent successors are a must-fail state

Rule 2: A state is a winning state when and only if it has at least one successor is a must-lose state

Boundary: This problem 0 is a must-lose state

Train of thought: from the bottom up to push, don ' t you?

PS: Recursion will burst stack.

Complete code:

/*0.399s*/
  
#include <bits/stdc++.h>
using namespace std;
  
BOOL dp[1000005];
int a[11];
  
int main ()
{
    int n, M, I, J;
    BOOL Flag;
    while (~SCANF ("%d%d", &n, &m))
    {for
        (i = 0; i < m; ++i)
            scanf ("%d", &a[i]);
        Sort (A, A + m);
        for (i = 1; I <= n; ++i)
        {
            flag = false;
            for (j = 0; J < m && I >= a[j]; ++j)
                if (!dp[i-a[j])
                {
                    flag = true;
                    break;
            Dp[i] = flag;
        }
        Puts (Dp[n]? "Stan wins": "Ollie wins");
    return 0;
}

Author: csdn Blog Synapse7

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

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.