HDU 1847 good luck in CET-4 everybody! (Bashi game theory)

Source: Internet
Author: User

Address: HDU 1847

This problem can be converted using NP state.

First, 0 means that you cannot play the cards. Then, it is a winning state that can reach the "fail" state in one step. What cannot reach the "fail" state in one step is a "fail" state. The state transition equation can be introduced and then solved using DP. That is, the transition from a known state to an unknown state is a small transition to a large state. If its next step is not defeated, it will be defeated, that is, it must win.

The Code is as follows:

#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;int dp[2000], a[100];int main(){    int n, i, j, m, flag;    a[0]=1;    for(i=1;; i++)    {        a[i]=a[i-1]*2;        if(a[i]>1000)        {            m=i;            break;        }    }    dp[0]=0;    for(i=1;i<=1000;i++)    {        flag=0;        for(j=0;j<m;j++)        {            if(a[j]>i)                break;            if(!dp[i-a[j]])            {                flag=1;                break;            }        }        if(flag)            dp[i]=1;        else            dp[i]=0;    }    while(scanf("%d",&n)!=EOF)    {        if(dp[n])            puts("Kiki");        else            puts("Cici");    }    return 0;}


HDU 1847 good luck in CET-4 everybody! (Bashi game theory)

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.