Problem Description
Digital deletions is a two-player game. The rule of the game is as following.
Begin by writing down a string of digits (numbers) that's as long or as short as you like. The digits can be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and appear in any combinations that you like. You don't have to use them all. Here is an example:
On a turn a player may either:
Change any one of the digits to a value less than the number that it is. (No negative numbers are allowed.) For example, you could change a 5 into a 4, 3, 2, 1, or 0.
Erase a zero and all the digits to the right of it.
The player who removes the last digit wins.
The game that begins with the string of numbers above could proceed like this:
Now, given a initial string, try to determine can the first player win if the two players play optimally both.
Begin by writing down a string of digits (numbers) that's as long or as short as you like. The digits can be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and appear in any combinations that you like. You don't have to use them all. Here is an example:
On a turn a player may either:
Change any one of the digits to a value less than the number that it is. (No negative numbers are allowed.) For example, you could change a 5 into a 4, 3, 2, 1, or 0.
Erase a zero and all the digits to the right of it.
The player who removes the last digit wins.
The game that begins with the string of numbers above could proceed like this:
Now, given a initial string, try to determine can the first player win if the two players play optimally both.
Input
The input consists of several test cases. For each case, there is a string in one line.
The length of string will be in the range of [1,6]. The string contains only digit characters.
Proceed to the end of file.
The length of string will be in the range of [1,6]. The string contains only digit characters.
Proceed to the end of file.
Output
Output Yes in a line if the first player can win the game, otherwise output No.
Sample Input
0 00 1 20
Sample Output
Yes Yes No No
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
/*
怪我眼瞎,把999999当成1e7,爆了7发内存
还有就是0应不应该取,应该去走,只是不能消除
当时我想的是能不能+1,把他换一种状态,导致脑子有时候就很难受
当时我想了想复杂度,感觉会爆掉,因为每次接近60次选择,可是我忘了数据
的范围,只有1e6,有时候就很难受
*/
const int maxn=1e6;
int dp[maxn];
char s[10]="999999";
int get_int(int len){
int ans=0;
for(int i=0;i<len;i++){
ans=ans*10+s[i]-'0';
}
return ans;
}
int dfs(int len){
if(len==0) return 0;
if(s[0]=='0') return 1;//注意001,这种情况
int num_s=get_int(len);
if(dp[num_s]!=-1) return dp[num_s];
dp[num_s]=0;
for(int i=0;i<len;i++){
char tmp=s[i];
if(tmp=='0') continue;
for(int j=s[i]-1-'0';j>=0;j--){//脑子里坏掉了
s[i]=j+'0';
if(!dfs(len)){
dp[num_s]=1;
break;
}
}
s[i]=tmp;
if(dp[num_s])break;
}
if(!dp[num_s]){
for(int i=0;i<len;i++){
if(s[i]=='0'){
if(!dfs(i)){
dp[num_s]=1;
break;
}
}
}
}
return dp[num_s];
}
void init(){
memset(dp,-1,sizeof(dp));
dp[0]=1;
dfs(6);
}
int main(){
init();
while(scanf("%s",s)==1){
int len=strlen(s);
if(dfs(len)) printf("Yes\n");
else printf("No\n");
}
return 0;
}