做法:
- 首先我们根据题意知道这两个人玩游戏,每次都是选取对自己最优的策略。
- 然后在数据规模上,n<=1000,完全可以用记忆化搜索。
- 每个人针对每个选项,都做出这一步的最优策略。然后进行模拟即可
AC代码:
#include<bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pb(x) push_back(x)
#define sz(x) (int)(x).size()
#define sc(x) scanf("%d",&x)
#define pr(x) printf("%d\n",x)
#define abs(x) ((x)<0?-(x):x)
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const double PI = 4*atan(1.0);
const int maxm = 1e8+5;
const int maxn = 1e4+5;
const int INF = 0x3f3f3f3f;
struct node
{
int a,b,c;
}val[1005];
int dp[1005][205];
int n,m,k,l;
int solve(int step,int score)
{
if(step == n+1) return score;
if(dp[step][score+100]!=INF)
return dp[step][score+100];
if(step&1){
int ans = -100;
if(val[step].a>0){
int mn = min(100,score+val[step].a);//
ans = max(ans,solve(step+1,mn));
}
if(val[step].b>0){
int mx = max(-100,score-val[step].b);//
ans = max(ans,solve(step+1,mx));
}
if(val[step].c>0){
ans = max(ans,solve(step+1,-score));
}
dp[step][score+100] = ans;
return ans;
}else{
int ans = 100;
if(val[step].a>0){
int mn = min(100,score+val[step].a);//
ans = min(ans,solve(step+1,mn));
}
if(val[step].b>0){
int mx = max(-100,score-val[step].b);//
ans = min(ans,solve(step+1,mx));
}
if(val[step].c>0){
ans = min(ans,solve(step+1,-score));
}
dp[step][score+100] = ans;
return ans;
}
}
int main()
{
#ifdef LOCAL_FILE
freopen("in.txt","r",stdin);
#endif // LOCAL
IO;
memset(dp,INF,sizeof(dp));
cin>>n>>m>>k>>l;
for(int i=1;i<=n;i++)
cin>>val[i].a>>val[i].b>>val[i].c;
int score = solve(1,m);
if(score>=k) cout<<"Good Ending"<<endl;
else if(score<k && score>l) cout<<"Normal Ending"<<endl;
else cout<<"Bad Ending"<<endl;
return 0;
}