POJ1157 little shop of flowers dp, poj1157dp

Source: Internet
Author: User

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;}

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.