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)