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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lpeaceminusone/article/details/82803091

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−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 .

That is, if there are three options in a selection, the score will be increased by 11, decreased by 11, or multiplied by -1−1. The score before the selection is 88. Then selecting option 11 will make the score become 99, and selecting option 22 will make the score 77 and select option 33 to make the score -8−8. Note that the score has an upper limit of 100100 and a lower limit of -100−100. If the score is 9999 at this time, an option that makes the score +2+2 is selected. After that, the score will change to 100100 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 kk, it will enter a good ending; if it is less than or equal to a certain value ll, 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 kk, ll 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 kk value, the ll 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,l(1\le n \le 10001≤n≤1000, -100 \le m \le 100−100≤m≤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 nn lines contains three integers a,b,ca,b,c(a\ge 0a≥0 , b\ge0b≥0 ,c=0c=0 or c=1c=1),indicates the options that appear in this selection,in which a=0a=0 means there is no option to increase the score in this selection, a>0a>0 means there is an option in this selection to increase the score by aa ; b=0b=0 means there is no option to decrease the score in this selection, b>0b>0 means there is an option in this selection to decrease the score by bb; c=0c=0 means there is no option to multiply the score by -1−1 in this selection , c=1c=1 means there is exactly an option in this selection to multiply the score by -1−1. It is guaranteed that a,b,ca,b,c are not equal to 00 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 徐州赛区网络预赛

两人玩选择游戏,每个选择题会有1~3个选项,只能选一个。每个选项都会影响游戏的得分。某些选项会增加分数,某些选项会降低分数,某些选项会将分数 * -1。 分数的上限是100分,下限为-100分。所有选择题做完后,如果最后的分数>=k,则为好结局,如果<=l则为坏结局,两个都不满足就是正常结局。现在,第一个人想要好结局,第二个人想要坏结局,两人依次轮流选择选项,第一个人首先选择。假设他们都知道初始分数,每个选项的影响,以及k,l的值,并决定以最适合它们的方式进行选择。(每个人都会尽力发挥他们想要的结局,如果不可能,他们宁愿正常结束也不会让他对手得到想要的结局。)现在给你k,l,以及每个选项对分数的影响,你能回答游戏的最终结局吗?(好、坏、正常结局)
输入n,m,k,l。n为题数,m为初始分数。k、l如上所述。接下来n行每行三个整数a,b,c。a=0表示没有选项可以增加分数,a>0表示选项中可以增加a分数,b=0表示没有选项可以降低分数,b>0表示有一个选项可以降低分数b,c=0表示没有选项可以乘-1,c=1表示有选项可以乘-1。保证a,b,c不同时为0。

每个都是选择题只选一项,开始以为是三个必须都选,迷茫了好长时间...

虽然记忆化搜索不是太会,但是看了大佬的博客还是理解了一点,还有dp的写法的,比较好懂一点。

#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define inf 0x3f3f3f
using namespace std;
#define mod 1000000007
const int maxn=100115;
int a[maxn],b[maxn],c[maxn];
int dp[maxn][210];
int n,m,k,l;
int dfs(int x,int s){
    if(dp[x][s]!=-1)return dp[x][s];
    if(x==n)return s;
    int aa,bb,cc;
    if(x&1)aa=bb=cc=201;
    else aa=bb=cc=-1;
    if(a[x])aa=dfs(x+1,min(200,a[x]+s));
    if(b[x])bb=dfs(x+1,max(0,s-b[x]));
    if(c[x])cc=dfs(x+1,200-s);
    if(x&1)dp[x][s]=min(min(aa,bb),cc);
    else
        dp[x][s]=max(max(aa,bb),cc);
    return dp[x][s];
}
int main(){
    while(~scanf("%d%d%d%d",&n,&m,&k,&l)){
        mem(dp,-1);
        m+=100;k+=100;l+=100;
        for(int i=0;i<n;i++){
            scanf("%d%d%d",&a[i],&b[i],&c[i]);
        }
        int ans=dfs(0,m);
        if(ans>=k)puts("Good Ending");
        else if(ans<=l)puts("Bad Ending");
        else
            puts("Normal Ending");
    }
}

猜你喜欢

转载自blog.csdn.net/lpeaceminusone/article/details/82803091
Ge
今日推荐