解脱
2024-07-18 17:01:12
发布于:北京
3阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
bool vis[105][105];
long long answer ;
char mp[105][105];
long long dp[105][105];
long long n,t,k,z,sx,sy;
int main()
{
int n;
cin >> n >> t >> k >> z >> sx >> sy;
for(int i = 1 ; i <= n ; i ++ ){
for(int j = 1 ; j <= n ; j ++ ){
cin >> mp[i][j];
}
}
dp[sx][sy] = t;
if(mp[sx][sy] == 'D')dp[sx][sy] += z;
for(int i = sx+1 ; i <= n ; i ++ ){
dp[i][sy] = dp[i-1][sy];
if(mp[i][sy] == 'D')dp[i][sy] += z;
if(mp[i][sy] == '.')dp[i][sy] -= 1;
if(mp[i][sy] == 'M')dp[i][sy] -= k;
}
for(int i = sy + 1 ; i <= n ; i ++ )
{
dp[sx][i] = dp[sx][i-1];
if(mp[sx][i] == 'D')dp[sx][i] += z;
if(mp[sx][i] == '.')dp[sx][i] -= 1;
if(mp[sx][i] == 'M')dp[sx][i] -= k;
}
for(int i = sx + 1 ; i <= n ; i ++ )
{
for(int j = sy + 1 ; j <= n ; j ++ )
{
if(mp[i][j] == 'D')dp[i][j] += z;
if(i==sx&&j==sy)continue;
dp[i][j] += max(dp[i-1][j],dp[i][j-1]);
if(mp[i][j] == '.')dp[i][j] -= 1;
if(mp[i][j] == 'M')dp[i][j] -= k;
}
}
cout <<dp[n][n] << endl;
return 0;
}
这里空空如也
有帮助,赞一个