POJ1157 LITTLE Shop of FLOWERS DP

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.