题解:
f[i][j]表示先后手最大差
g[i][j]表示在最大差的时候是否有后手没得走
代码:
#include<bits/stdc++.h> using namespace std; const int N=105; int n,m,q,x,y,a[N][N]; double f[N][N]; char s[105]; int can(int x,int y){return x<=n&&y<=m&&a[x][y]>=0;} int main() { scanf("%d%d",&n,&m); gets(s); for (int i=1;i<=n;i++) { gets(s+1); for (int j=1;j<=m;j++) { if (s[j]=='.')a[i][j]=0; if (s[j]=='#')a[i][j]=-1; if (s[j]=='H'||s[j]=='C')a[i][j]=1; if (s[j]=='F'||s[j]=='S')a[i][j]=3; if (s[j]=='I'||s[j]=='B')a[i][j]=5; } } for (int i=n;i;i--) for (int j=m;j;j--) if (a[i][j]>=0) { int flag=1; double z=-1e10; if (can(i,j+1)) flag=0,z=max(z,a[i][j+1]-f[i][j+1]); if (can(i+1,j)) flag=0,z=max(z,a[i+1][j]-f[i+1][j]); if (can(i+1,j+1)) flag=0,z=max(z,a[i+1][j+1]-f[i+1][j+1]); f[i][j]=z; if (flag) f[i][j]=-0.5; } scanf("%d",&q); while (q--) { scanf("%d%d",&x,&y); printf("%s\n",f[x][y]>0?"HAL":"DAVE"); } return 0; }