ACM-ICPC 2018 徐州赛区网络预赛 B BE, GE or NE (记忆化dfs)

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 llvalue, 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=0means 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,care 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[x][s]表示分数为s,选第x道题的时候的最优值。(第一个人最大,第二个人最小) dfs记忆化一下就好了。注意分数为-100~100,所以分数全都+100。

比赛的时候想到了dp,但是第二维愣是没想到是分数,最后也没做出来。看来对记忆化搜索的题型不敏感。

代码:

#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=1e3+10;
int n,m,k,l,t;
int dp[maxn][maxn];
int a[maxn],b[maxn],c[maxn];
int ans;
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,s+a[x]));
    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()
{
    int T,cas=1;
    while(scanf("%d%d%d%d",&n,&m,&k,&l)!=EOF)
    {
        m+=100;
        k+=100;l+=100;//!!!
        for(int i=0;i<n;i++)
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
        memset(dp,-1,sizeof(dp));
        ans=dfs(0,m);
        if(ans>=k) puts("Good Ending");
        else if(ans<=l) puts("Bad Ending");
        else puts("Normal Ending");
    }
    return 0;
}

 

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值