poj 1157 LITTLE SHOP OF FLOWERS 【简单DP】

//dp[i][j]=max(dp[i][j-1]+a[i][j],dp[i][j-1]);
#include<iostream>
#include<cstdio>
using namespace std;
const int inf=0x3f3f3f3f;
int dp[110][110];

int main()
{
    int n,m,tmp,ans=-inf;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        dp[i][0]=-inf;
        for(int j=1;j<=m;j++){
            scanf("%d",&tmp);
            dp[i][j]=max(dp[i][j-1],dp[i-1][j-1]+tmp);
        }
    }
    cout<<dp[n][m]<<endl;
    return 0;
}


你可能感兴趣的:(poj 1157 LITTLE SHOP OF FLOWERS 【简单DP】)