Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- int n,w,h;
- char buf[100][102];
- int dp[101][101][101];
- int min(int a, int b){
- return a < b ? a : b;
- }
- int max(int a, int b){
- return a > b ? a : b;
- }
- #define neginf -10001
- int scoretbl[] = {
- neginf, neginf, 0, 0, 0, 0, 0, neginf, neginf, 0, 0, neginf, neginf, 0, 2, 1, 0, 0, 1, 1, 0, 0, 0
- };
- static int solve(){
- for(int x = 0; x < h; x++){
- for(int y = 0; y < w; y++){
- int z = x+y;
- int lim = min(h, z+1);
- for(int nx = z >= w ? z - w + 1: 0; nx < lim; nx++){
- int ny = z-nx;
- int ans = scoretbl[buf[x][y]+buf[nx][ny]-70+(x == nx)];
- if(ans < 0){
- dp[x+1][y+1][nx+1] = -1;
- continue;
- }
- dp[x+1][y+1][nx+1] = max(max(max(dp[x+1][y][nx+1], dp[x+1][y][nx]), dp[x][y+1][nx+1]), dp[x][y+1][nx])+ans;
- }
- }
- }
- }
- int main(){
- scanf("%d\n", &n);
- while(n--){
- scanf("%d %d\n", &w, &h);
- for(int i = 0; i<h; i++){
- scanf("%s", buf[i]);
- }
- solve();
- printf("%d\n", dp[h][w][h]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement