题目
解
设f[i][j]为第i朵花插到第j个花盆的最大美观度。
代码
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
int ff, v, w[1001][1001], f[1001][1001], ans;
int main(){
freopen("flower.in","r",stdin);
freopen("flower.out","w",stdout);
memset(f,-0x7f,sizeof(f));
scanf("%d%d", &ff, &v);
for(int i = 1; i <= ff; ++i)
for(int j = 1; j <= v; ++j)
scanf("%d", &w[i][j]); //i花放j花瓶价值
f[0][0] = 0;
for(int i = 1; i <= ff; ++i){ //花
for(int j = 1; j <= v; ++j){ //放第j花瓶
// f[i][j] = max(f[i-1][j], f[i][j-1]); //比赛时傻傻瞎打了这一句,导致WA...
for(int k = 0; k < j; ++k)
f[i][j] = max(f[i][j], f[i-1][k] + w[i][j]);
}
}
for(int j = 0; j <= v; ++j) //输出最大的
ans = max(ans, f[ff][j]);
printf("%d", ans);
fclose(stdin);
fclose(stdout);
}