POJ Topic 1157 LITTLE Shop of FLOWERS (DP)

Source: Internet
Author: User

LITTLE Shop of FLOWERS
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 19457 Accepted: 8966

Description

You want to arrange the window of your flower, a most pleasant. You have an F bunches of flowers, each being of a different kind, and at least as many vases ordered in a row. The vases is glued onto the shelf and being numbered consecutively 1 through V, where V is the number of vases, from left T o The vase 1 is the leftmost, and the vase V is the rightmost vase. The bunches is moveable and is uniquely identified by integers between 1 and F. These id-numbers has a significance:they determine the required order of appearance of the flower bunches in the row of Vases So, the bunch I must is in a vase to the left of the vase containing bunch J whenever I < J. Suppose, for Exa Mple, you have bunch of azaleas (id-number=1), a bunch of begonias (id-number=2) and a bunch of carnations (id-number=3). Now, all the bunches must is put into the vases keeping their id-numbers in order. The bunch of azaleas must is in a vase to the left of begonias, and the bunch of BEgonias must is in a vase to the left of carnations. If There is more vases than bunches of flowers then the excess would be is left empty. A Vase can hold is only one bunch of flowers.

Each vase have a distinct characteristic (just like flowers do). Hence, putting a bunch of flowers in a vase results in a certain aesthetic value, expressed by an integer. The aesthetic values is presented in a table as shown below. Leaving a vase empty has an aesthetic value of 0.

V A s E s

1

2

3

4

5

bunches

1 (azaleas)

< Span style= "font-size:14px" >7 23 -5 -24 16

2 (begonias)

5 21 -4 10 23

3 (carnations)

-21

5 -4 -20 20

According to the table, azaleas, for example, would look great on vase 2, but they would look awful in vase 4.

To achieve the most pleasant effect you had to maximize the sum of aesthetic values for the arrangement while keeping the Required ordering of the flowers. If more than one arrangement have the maximal sum value, any one of the them would be acceptable. You have to produce exactly one arrangement.

Input

    • The first line contains and numbers: F, V.
    • The following F Lines:each of these lines contains V integers, so thisAij is given as the jth number on the (I+ 1)St Line of the input file.


    • 1 <= F <= The where F is the number of the bunches of flowers. The bunches is numbered 1 through F.
    • F <= v <=, where V is the number of vases.
    • -50 <= Aij <= where Aij is the aesthetic value obtained by putting the flower bunch I into the vase J.

Output

The first line would contain the sum of aesthetic values for your arrangement.

Sample Input

3 57 23-5-24 165 21-4 10 23-21 5-4-20 20

Sample Output

53

Source

IOI 1999 The main idea: there are n flowers, M vase, the flower number I into the vase number J, the number of flowers than I, can only be inserted into the number of the J-size vase, each different number inserted in different numbers of vases have a value, to plug the n bouquet of the earned value of the AC code
#include <stdio.h> #include <string.h> #define INF 0xfffffff#define Max (A, B) (a>b?a:b) int map[1010][1010 ],dp[1010][1010];void init (int n,int m) {int i,j;for (i=1;i<=n;i++) for (j=1;j<=m;j++) Dp[i][j]=-inf;} int main () {int n,m;while (scanf ("%d%d", &n,&m)!=eof) {int i,j,k;for (i=1;i<=n;i++) {for (j=1;j<=m;j++) { scanf ("%d", &map[i][j]);}} Init (n,m); for (j=1;j<=m;j++) dp[1][j]=map[1][j];for (i=2;i<=n;i++) {for (j=1;j<=m;j++) {for (k=1;k<j;k++) Dp[i][j]=max (Dp[i][j],dp[i-1][k]+map[i][j]);}} int Ans=-inf;for (i=1;i<=m;i++) {Ans=max (ans,dp[n][i]);} printf ("%d\n", ans);}}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ topic 1157 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.