ACM-ICPC 2018 徐州赛区网络预赛 B题 (递推+dp)

题目链接:https://nanti.jisuanke.com/t/31454

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-313 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 -11 .

That is, if there are three options in a selection, the score will be increased by 11, decreased by 11, or multiplied by -11. 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 -88. Note that the score has an upper limit of 100100and a lower limit of -100100. 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 10001n1000, -100 \le m \le 100100m100 , -100 \le l < k \le 100100l<k100 ), 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 0a0 , b\ge0b0 ,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>0means 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 -11 in this selection , c=1c=1 means there is exactly an option in this selection to multiply the score by -11. 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

题意:这题目感觉就是一篇长篇阅读题,英语真的很重要,不然的话很容易读错题意。。。

Koutarou和Sena两个人轮流按顺序做n个选择题,Koutarou先做,假设(n=5),Koutarou做1,3,5,Sena做2,4,初始分数为m。

每个题目有3个选项(a,b,c),a表示+a分,b表示-b分,c表示乘-1(0<=c<=1),a,b,c等于0表示对应选项不可选,比赛结束后的分数为sum。

Koutarou希望得到GE结果,Sena希望得到BE结果,if(sum>=k) 输出GE,if(sum<=L) 删除BE,都不满足输出NE。

思路:设dp[i][j]表示在第i个题目中,原来的分数为j时所能获得的最大的分数。

要得到GE结果,分数越高越好,要得到BE结果,分数越低越好,因此Koutarou的策略应当是取尽可能大的,Sena的策略应当是取尽可能小的。

状态转移方程:

j取值范围为-100~100,可能为负数,+100转化为0~200

op1=dp[i+1][min(j+a[i],100)+100]; //第i个题目选择a选项后的得分
op2=dp[i+1][max(j-b[i],-100)+100];
op3=dp[i+1][-j+100];

Koutarou做题时:

dp[i][j+100]=max(dp[i][j+100],op1);
dp[i][j+100]=max(dp[i][j+100],op2);
dp[i][j+100]=max(dp[i][j+100],op3);

Sena做题时:

dp[i][j+100]=min(dp[i][j+100],op1);
dp[i][j+100]=min(dp[i][j+100],op2);
dp[i][j+100]=min(dp[i][j+100],op3);

AC代码:

#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
using namespace std;
int dp[1010][210],n,m,k,l;
int a[1010],b[1010],c[1010];
int main()
{
	while(~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++)  //初始化 -100~100转化为 0~200 
		dp[n+1][i+100]=i;
		for(int i=n;i>=1;i--)
			for(int j=-100;j<=100;j++)
			{
				int op1=dp[i+1][min(j+a[i],100)+100];  //第i个题目选择a选项后的得分 
				int op2=dp[i+1][max(j-b[i],-100)+100];
				int op3=dp[i+1][-j+100];
				if(i%2)  //Koutarou做 
				{
					dp[i][j+100]=-100;	
					if(a[i])dp[i][j+100]=max(dp[i][j+100],op1);
					if(b[i])dp[i][j+100]=max(dp[i][j+100],op2);
					if(c[i])dp[i][j+100]=max(dp[i][j+100],op3);
				}
				else//Sena做 
				{
					dp[i][j+100]=100;	
					if(a[i])dp[i][j+100]=min(dp[i][j+100],op1);
					if(b[i])dp[i][j+100]=min(dp[i][j+100],op2);
					if(c[i])dp[i][j+100]=min(dp[i][j+100],op3);	
				}
			}
		if(dp[1][m+100]>=k) printf("Good Ending\n");
		else if(dp[1][m+100]<=l)printf("Bad Ending\n");
		else printf("Normal Ending\n");
	}
}
 

  

 

 
posted @ 2018-09-10 20:04  ccsu_dj辉  阅读(369)  评论(0编辑  收藏  举报