BE, GE or NE(记忆化搜索(博弈类))

本文介绍了一个独特的游戏系统,玩家在游戏过程中面临多种选择,每种选择会影响游戏得分,并最终决定游戏结局。通过记忆化搜索算法,分析了两位玩家如何根据初始得分及目标得分范围合作达成最优结局。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named "Sena" are playing a video game. The game system of this video game is quite unique: in the process of playing this game, you need to constantly face the choice, each time you choose the game will provide 1−31-31−3 options, the player can only choose one of them. Each option has an effect on a "score" parameter in the game. Some options will increase the score, some options will reduce the score, and some options will change the score to a value multiplied by −1-1−1 .

That is, if there are three options in a selection, the score will be increased by 111, decreased by 111, or multiplied by −1-1−1. The score before the selection is 888. Then selecting option 111 will make the score become 999, and selecting option 222 will make the score 777 and select option 333 to make the score −8-8−8. Note that the score has an upper limit of 100100100 and a lower limit of −100-100−100. If the score is 999999 at this time, an option that makes the score +2+2+2 is selected. After that, the score will change to 100100100 and vice versa .

After all the choices have been made, the score will affect the ending of the game. If the score is greater than or equal to a certain value kkk, it will enter a good ending; if it is less than or equal to a certain value lll, it will enter the bad ending; if both conditions are not satisfied, it will enter the normal ending. Now, Koutarou and Sena want to play the good endings and the bad endings respectively. They refused to give up each other and finally decided to use the "one person to make a choice" way to play the game, Koutarou first choose. Now assume that they all know the initial score, the impact of each option, and the kkk, lll values, and decide to choose in the way that works best for them. (That is, they will try their best to play the ending they want. If it's impossible, they would rather normal ending than the ending their rival wants.)

Koutarou and Sena are playing very happy, but I believe you have seen through the final ending. Now give you the initial score, the kkk value, the lll value, and the effect of each option on the score. Can you answer the final ending of the game?

Input

The first line contains four integers n,m,k,ln,m,k,ln,m,k,l(1≤n≤10001\le n \le 10001≤n≤1000, −100≤m≤100-100 \le m \le 100−100≤m≤100 , −100≤l<k≤100-100 \le l < k \le 100−100≤l<k≤100 ), represents the number of choices, the initial score, the minimum score required to enter a good ending, and the highest score required to enter a bad ending, respectively.

Each of the next nnn lines contains three integers a,b,ca,b,ca,b,c(a≥0a\ge 0a≥0 , b≥0b\ge0b≥0 ,c=0c=0c=0 or c=1c=1c=1),indicates the options that appear in this selection,in which a=0a=0a=0 means there is no option to increase the score in this selection, a>0a>0a>0 means there is an option in this selection to increase the score by aaa ; b=0b=0b=0 means there is no option to decrease the score in this selection, b>0b>0b>0 means there is an option in this selection to decrease the score by bbb; c=0c=0c=0 means there is no option to multiply the score by −1-1−1 in this selection , c=1c=1c=1 means there is exactly an option in this selection to multiply the score by −1-1−1. It is guaranteed that a,b,ca,b,ca,b,c are not equal to 000 at the same time.

Output

One line contains the final ending of the game. If it will enter a good ending,print "Good Ending"(without quotes); if it will enter a bad ending,print "Bad Ending"(without quotes);otherwise print "Normal Ending"(without quotes).

样例输入1

3 -8 5 -5
3 1 1
2 0 1
0 2 1

样例输出1

Good Ending

样例输入2

3 0 10 3
0 0 1
0 10 1
0 2 1

样例输出2

Bad Ending

题目来源

ACM-ICPC 2018 徐州赛区网络预赛

思路:记忆化搜索。。。这种题目还是很经典的,许多博弈问题都是可以这样做的。

代码:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1000+10;
int n,m,k,l,t;
int dp[maxn][maxn];
int a[maxn],b[maxn],c[maxn];

int dfs(int num,int state){
  ///  cout<<"state:"<<state<<endl;

    if(state>=200)
        state=200;
    if(state<=0)
        state=0;
    if(dp[num][state]!=-1)
        return dp[num][state];
    if(num==n+1)
    {
        return state;
    }
    int aa,bb,cc;
    if(num%2==1)///说明是先手
    {
        aa=bb=cc=0;
    }
    else
    {
        aa=bb=cc=200;
    }
    
    
    if(a[num]){
        aa=dfs(num+1,state+a[num]);
    }
    if(b[num]){
        bb=dfs(num+1,state-b[num]);
    }
    if(c[num]==1){
        cc=dfs(num+1,200-state);///取反操作
    }
    if(num%2==1){///说明是先手;
        dp[num][state]=max(max(aa,bb),cc);
        ///return max(max(aa,bb),cc);
    }
    else{
         dp[num][state]=min(min(aa,bb),cc);
       /// return min(min(aa,bb),cc);
    }
    return dp[num][state];
}
int main()
{
    scanf("%d%d%d%d",&n,&m,&k,&l);
    memset(dp,-1,sizeof(dp));

    for(int i=1;i<=n;i++){
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
    }
    int ans=dfs(1,m+100);
   /// cout<<ans<<endl;
    if(ans>=k+100)
        cout<<"Good Ending"<<endl;
    else if(ans<=l+100)
        cout<<"Bad Ending"<<endl;
    else
        cout<<"Normal Ending"<<endl;

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值