1327: PIPI的炸弹

dp博弈

#include <bits/stdc++.h>
using namespace std;
int x,a,b;
const int N=1e6+10;
int dp[N];  //1代表先手赢,-1代表先手输 
int fun(int x){
	if(dp[x]!=0){
		return dp[x];
	}
	if(x==0){
		dp[0]=-1;
		return -1;
	}
	else if(x<=a){
		dp[x]=-fun(x-1);
		return dp[x];
	}
	else if(x>a&&x<=b+1){
		dp[x]=1;
		return dp[x];
	}
	else {
		int flag=0;
		flag = -fun(x-1);
		if(flag == 1){
			dp[x]=1;
			return 1;
		} 
		for(int j=a;j<=b;j++){
			flag=-fun()x-j-1);
			if(flag==1){
				dp[x]=1;
				return 1;
			}
		}
		dp[x]=-1;
		return -1;
	}
}
int main(){

	while(scanf("%d%d%d",&x,&a,&b)!=EOF){
		
		if(fun(x)==1){
			printf("PIPI\n");
		}
		else 
			printf("POPO\n");
	}
	return 0;
}
posted @ 2026-03-12 22:04  peter_shen  阅读(9)  评论(0)    收藏  举报