POJ1157 little shop of flowers dp, poj1157dp
Question
Http://poj.org/problem? Id = 1157
Theme
There are f flowers and k bottles. Each flower contains a specific aesthetic value for each bottle. Ask the maximum aesthetic value. note that flower I cannot appear after a flower larger than flower I. what is the maximum aesthetic value?
Solutions
Dp [I] [j] indicates the maximum aesthetic value for inserting the I flower into the k bottle.
The state transition equation is dp [I] [j] = max (dp [I-1] [(I-1 )~ (K-f + i-1)]) + value [I] [j]
Code
#include <cstdio>const int maxn = 110;int f,k;int v[maxn][maxn];int dp[maxn][maxn];int main(){ scanf("%d%d",&f,&k); for(int i = 1 ; i <= f ; i ++) { for(int j = 1 ; j <= k ; j ++) scanf("%d",&v[i][j]); } for(int i = 1 ; i <= k-f+1 ; i ++) dp[1][i] = v[1][i]; //dp for(int i = 2; i <= f ; i ++) { for(int j = i ; j <= k-f+i ; j ++) { int ma = -100000000; for(int kk = i-1 ; kk < j ; kk ++) { if(ma < dp[i-1][kk]) ma = dp[i-1][kk]; } dp[i][j] = ma+v[i][j]; } } int ma = -10000000; for(int i = f ; i <= k ; i ++) if(ma < dp[f][i]) ma = dp[f][i]; printf("%d\n",ma); return 0;}