poj 1157 LITTLE SHOP_简单dp

时间:2023-01-21 22:56:50

题意:给你n种花,m个盆,花盆是有顺序的,每种花只能插一个花盘i,下一种花的只能插i<j的花盘,现在给出价值,求最大价值

简单dp

#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 110
int dp[N][N],a[N][N];
int main(int argc, char** argv) {
int n,m,i,j;
while(scanf("%d%d",&n,&m)!=EOF){
memset(dp,0,sizeof(dp));
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
scanf("%d",&a[i][j]);
for(i=1;i<=n;i++)
for(j=i;j<=m;j++){
dp[i][j]=dp[i-1][j-1]+a[i][j];
if(j>i)
dp[i][j]=max(dp[i][j],dp[i][j-1]);
}
printf("%d\n",dp[n][m]);
}
return 0;
}