题目链接:点击打开链接
博弈论刷题笔记~~~
水题,不解释,这个题目我是用状压+dfs做的,不过同理也可以用SG函数做~~~
话说博弈论中的数学思维题让我这种数学渣渣很头疼啊~~~Orz,Orz,Orz
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const int power[]={1,10,100,1000,10000,100000,1000000};
const int MAXN=1000000;
char str[10];
int dp[MAXN];
int dfs(int status,int Ls)
{
if(str[0]=='0') return 1;
if(Ls==0) return -1;
if(dp[status]) return dp[status];
//如果后继有一个输了的情况,那么获胜
bool flag=false;
for(int i=0;i<Ls;i++)
{
int sn=str[i]-'0';
for(int j=0;j<sn;j++)
{
str[i]=j+'0';
int nxt=status-(sn-j)*power[Ls-i-1];
flag|=(dfs(nxt,Ls)==-1);
str[i]=sn+'0';
}
}
for(int i=0;i<Ls;i++)
if(str[i]=='0')
{
int nxt=status/power[Ls-i];
flag|=(dfs(nxt,Ls-1)==-1);
}
return dp[status]=flag?1:-1;
}
int main()
{
while(scanf("%s",str)!=EOF)
{
int status=atoi(str);
int flag=dfs(status,strlen(str));
puts(flag==1?"Yes":"No");
}
return 0;
}