题解 | #字母收集#

字母收集

https://www.nowcoder.com/practice/9740ce2df0a04399a5ade1927d34c1e1

#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
const int N = 510;

int dp[N][N];
int n, m;
int main() {
    scanf("%d%d", &n, &m);
    char tmp;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            scanf(" %c", &tmp);
            if (tmp == 'l') {
                dp[i][j] = 4;
            } else if (tmp == 'o') {
                dp[i][j] = 3;
            } else if (tmp == 'v') {
                dp[i][j] = 2;
            } else if (tmp == 'e') {
                dp[i][j] = 1;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            dp[i][j] += max(dp[i][j - 1], dp[i - 1][j]);
        }
    }
    printf("%d", dp[n][m]);
    return 0;
}

全部评论

相关推荐

牛客717484937号:双飞硕没实习挺要命的
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务