1. 程式人生 > >ACM-ICPC 2018 徐州賽區網路預賽 B(dp)

ACM-ICPC 2018 徐州賽區網路預賽 B(dp)

傳送門

題面:

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

題目來源

題意:

    有兩個人在玩遊戲,他們最開始有積分m分,如果最終的積分val>=k,則進入Bad Ending,如果最終積分val<l 則進入Good Ending。現在一共有n個關卡,每個選項有三個選項a,b,c,a代表使得積分+a,b代表使得積分+b,c==1代表使得積分*-1。如果a或b等於0,則不能選擇,題目保證a,b,c不同時為0,A先選,B後選,A想要進入GE,B想要進入BE,他們都會進行最優的操作,問你最後的結局。

題目分析:

     因為要滿足GE,分數越高越好,而要滿足BE,分數越低越好,因此A的策略應當是取儘可能大的,B的策略應當是取儘可能小的。此時我們不妨用dp去解決。

    我們設dp[i][j]表示在第i個關卡中,分數為j分時所能獲得的最大的分數。而因為會有abc三種選項的狀態轉移,則對於三個狀態分別有

    而對於i為奇數情況下是A選,則i的狀態要優先選最大值;而對於i為偶數的情況下B選,則優先選最小。

    而需要注意的是,因為j的值可能為負數,因此我們可以用map(常數較大)或者直接將j+100去遞推dp。

程式碼:

#include <bits/stdc++.h>
#define maxn 1005
using namespace std;
int dp[maxn][205];
int a[maxn],b[maxn],c[maxn];
const int bit=100;
int main()
{
    int n,m,k,l;
    scanf("%d%d%d%d",&n,&m,&k,&l);
    for(int i=1;i<=n;i++){
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
    }
    for(int i=-100;i<=100;i++){
        dp[n+1][i+bit]=i;
    }
    for(int i=n;i>=1;i--){
        for(int j=-100;j<=100;j++){
            int o1=dp[i+1][min(j+a[i],100)+bit];
            int o2=dp[i+1][max(j-b[i],-100)+bit];
            int o3=dp[i+1][-j+bit];
            if(i&1){
                dp[i][j+bit]=-100;
                if(a[i]) dp[i][j+bit]=max(dp[i][j+bit],o1);//狀態轉移
                if(b[i]) dp[i][j+bit]=max(dp[i][j+bit],o2);
                if(c[i]) dp[i][j+bit]=max(dp[i][j+bit],o3);
            }
            else {
                dp[i][j+bit]=100;
                if(a[i]) dp[i][j+bit]=min(dp[i][j+bit],o1);
                if(b[i]) dp[i][j+bit]=min(dp[i][j+bit],o2);
                if(c[i]) dp[i][j+bit]=min(dp[i][j+bit],o3);
            }
        }
    }
    if(dp[1][m+bit]>=k) puts("Good Ending");
    else if(dp[1][m+bit]<=l) puts("Bad Ending");
    else puts("Normal Ending");
    return 0;
}