Topic
http://poj.org/problem?id=1157
Main topic
There are f flowers, K bottles, each flower each bottle has a specific aesthetic value, asking what is the maximum aesthetic value. Note that the flower I cannot appear in the back of a flower greater than I. Q What is the maximum aesthetic value?
Thinking of solving problems
DP[I][J] represents the maximum aesthetic value of inserting the first 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>ConstintMAXN = the;intF,k;intV[MAXN][MAXN];intDP[MAXN][MAXN];intMain () {scanf ("%d%d", &f,&k); for(inti =1; I <= F; i + +) { for(intj =1; J <= K; J + +) scanf ("%d", &v[i][j]); } for(inti =1; I <= k-f+1; i + +) dp[1][i] = v[1][i];//DP for(inti =2; I <= F; i + +) { for(intj = i; J <= K-f+i; J + +) {int Ma= -100000000; for(intKK = i1; 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(inti = f; I <= K; i + +)if(Ma< Dp[f][i])Ma= Dp[f][i];printf("%d\ n",Ma);return 0;}
POJ1157 LITTLE Shop of FLOWERS DP