[DP]poj3176 Cow Bowling

来源:互联网 发布:python 渗透测试 编辑:程序博客网 时间:2024/05/16 02:45

poj3176 Cow Bowling

题意:

7         *        3   8       *      8   1   0       *    2   7   4   4       *  4   5   2   6   5

到达某点后,只能像左下或右下走,累计所得分数,求分数最大值

思路:

水题,简单dp

状态转移方程:dp[i][j] = max(dp[i+1][j],dp[i+1][j+1]) + a[i][j];

代码:

#include <iostream>#include <stdio.h>using namespace std;const int maxn = 400;int a[maxn][maxn];int dp[maxn][maxn];int n, ans=0;int main(){    int n;    scanf("%d", &n);    for(int i=1; i<=n; i++)    for(int j=1; j<=i; j++)        scanf("%d", &a[i][j]);    for(int i=1; i<=n; i++)        dp[n][i] = a[n][i];    for(int i=n-1; i>0; i--)    for(int j=1; j<=i; j++)        dp[i][j] = max(dp[i+1][j],dp[i+1][j+1]) + a[i][j];    printf("%d", dp[1][1]);    return 0;}


0 0