Game in Momotetsu World
Game in Momotetsu World
零和博弈, 二维dp找均衡路径
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e8;
void solve() {
int h, w; cin >> h >> w;
vector<string> g(h);
for(int i = 0; i < h; i ++) cin >> g[i];
vector<int> dp(w, -INF);
for(int i = h - 1; i >= 0; i --) {
vector<int> ndp = dp;
for(int j = w - 1; j>= 0; j --) {
int r = -INF;
if(j+1 < w) {
int k = ((g[i][j+1] == '+') - (g[i][j+1] == '-'));
r = max(k - dp[j+1], r);
}
if(i+1 < h) {
int k = ((g[i+1][j] == '+') - (g[i+1][j] == '-'));
r = max(k - ndp[j], r);
}
dp[j] = r;
if(i==h-1&&j==w-1) dp[j]=0;
}
}
if(dp[0] == 0) cout << "Draw\n";
else if(dp[0] > 0) cout << "Takahashi\n";
else cout << "Aoki\n";
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int _ = 1; //cin >> _;
while(_--) solve();
return 0;
}

浙公网安备 33010602011771号