链接https://nanti.jisuanke.com/t/31454
#include<bits/stdc++.h>
#define st 100
#define M 1005
using namespace std;
int f[M][500],n,m,l,r,a[M],b[M],c[M],ret,i;
int dfs(int d,int p){
if(d==n){
if(p<=l)return 4;else if(p>=r)return 1;else return 2;
}
int &ans=f[d][p+st];
if(ans!=-1)return ans;
int win,los,ok=0,tp;
if(d&1){win=4;los=1;}else{win=1;los=4;}
if(a[d]){
tp=dfs(d+1,min(100,p+a[d]));
if(tp==win)return ans=win;
if(tp==2) ok=1;
}
if(b[d]){
tp=dfs(d+1,max(-100,p-b[d]));
if(tp==win)return ans=win;
if(tp==2)ok=1;
}
if(c[d]){
tp=dfs(d+1,-p);
if(tp==win)return ans=win;
if(tp==2)ok=1;
}
if(ok)return ans=2;
return ans=los;
}
int main(){
memset(f,-1,sizeof(f));
scanf("%d%d%d%d",&n,&m,&r,&l);
for(i=0;i<n;i++)scanf("%d%d%d",&a[i],&b[i],&c[i]);
ret=dfs(0,m);
if(ret==1)cout<<"Good Ending"<<endl;
else if(ret==4)cout<<"Bad Ending"<<endl;
else cout<<"Normal Ending"<<endl;
}
ACM-ICPC 2018 徐州赛区网络预赛 B BE, GE or NE(博弈,记忆化搜索)
原文:https://www.cnblogs.com/VIrtu0s0/p/9623614.html