`
Simone_chou
  • 浏览: 192511 次
  • 性别: Icon_minigender_2
  • 来自: 广州
社区版块
存档分类
最新评论

LITTLE SHOP OF FLOWERS(DP)

    博客分类:
  • POJ
 
阅读更多
LITTLE SHOP OF FLOWERS
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 18300   Accepted: 8435

Description

You want to arrange the window of your flower shop in a most pleasant way. You have F bunches of flowers, each being of a different kind, and at least as many vases ordered in a row. The vases are glued onto the shelf and are numbered consecutively 1 through V, where V is the number of vases, from left to right so that the vase 1 is the leftmost, and the vase V is the rightmost vase. The bunches are moveable and are uniquely identified by integers between 1 and F. These id-numbers have a significance: They determine the required order of appearance of the flower bunches in the row of vases so that the bunch i must be in a vase to the left of the vase containing bunch j whenever i < j. Suppose, for example, 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 be put into the vases keeping their id-numbers in order. The bunch of azaleas must be in a vase to the left of begonias, and the bunch of begonias must be in a vase to the left of carnations. If there are more vases than bunches of flowers then the excess will be left empty. A vase can hold only one bunch of flowers. 

Each vase has 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 are 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)

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 in vase 2, but they would look awful in vase 4. 

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

Input

  • The first line contains two numbers: FV.
  • The following F lines: Each of these lines contains V integers, so that Aij is given as the jth number on the (i+1)st line of the input file.


  • 1 <= F <= 100 where F is the number of the bunches of flowers. The bunches are numbered 1 through F. 
  • F <= V <= 100 where V is the number of vases. 
  • -50 <= Aij <= 50 where Aij is the aesthetic value obtained by putting the flower bunch i into the vase j.

Output

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

Sample Input

3 5
7 23 -5 -24 16
5 21 -4 10 23
-21 5 -4 -20 20

Sample Output

53

 

     题意:

     给出 F(1 ~ 100) 和 V ( F ~ 100),代表有 F 个花种,V 个花瓶,现在每朵花都要选一个花瓶放置,花对应所在花瓶对应会有一个健康值。问如何放置使总和值最大,且花种的摆放顺序一定要递增。

 

     思路:

     DP。 dp [ i ] [ j ] 为第 i 种花放置在 j 花瓶时所达到的最大值,所以 dp [ i ] [ j ] = max { dp [ i - 1 ] [ k ] ( 1 <= k < j) } + num [ i ] [ j ]。最后比较最大值输出即可。

 

     AC:

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int INF = 99999999;

int num[105][105], dp[105][105];

int main() {

    int n, m;
    scanf("%d%d", &n, &m);

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            scanf("%d", &num[i][j]);
            if (i == 1) {
                dp[i][j] = num[i][j];
                ans = max(ans, dp[i][j]);
            }
        }
    }

    int ans = -INF;
    for (int i = 2; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            int Max = -INF;
            for (int k = 1; k < j; ++k) {
                Max = max(Max, dp[i - 1][k]);
            }

            dp[i][j] = Max + num[i][j];
            if (i == n) ans = max(ans, dp[i][j]);
        }
    }

    printf("%d\n", ans);

    return 0;
}

 

 

 

分享到:
评论

相关推荐

    Pku acm 第1157题 LITTLE SHOP OF FLOWERS c代码

    Pku acm 第1157题 LITTLE SHOP OF FLOWERS c代码,有详细的注释,动态规划

    2023最新深度学习袖珍书《The Little Book of Deep Learning》.pdf

    《The Little Book of Deep Learning》是一本由François Fleuret编写的深度学习袖珍书籍,旨在为读者提供深度学习的基础知识和技术概览。这本书共有140页,涵盖了深度学习的多个关键方面,包括机器学习基础、计算...

    The little book of Thermofluids

    根据提供的信息,《The Little Book of Thermofluids》是一本专为机械工程领域的学生与从业者设计的专业书籍。本书第3版由多位作者共同编写完成,包括S.B. Beck、S.G. Blakey、M.W. Brown、S.B. Chin、F.C.G.A. ...

    The Little World of Liz Climo (你今天真好看)

    标题和描述中提到的《The Little World of Liz Climo(你今天真好看)》是一本由知名画师Liz Climo创作的图书。Liz Climo是一位插画家,以其简洁幽默的画风和温馨可爱的动物角色而闻名。她的作品通常以动物为原型,...

    The Little Book of Semaphores

    The Little Book of Semaphores is a textbook that introduces the principles of synchronization for concurrent programming. In most computer science curricula, synchronization is a module in an ...

    John C. Bogle-The Little Book of Common Sense Investing

    the Little Book of Common Sense Investing

    A Little Book of R For Time Series

    《R语言时间序列分析教程》是Avril Coghlan撰写的,旨在向读者介绍如何利用R语言进行时间序列的分析。R语言是一种广泛使用的免费统计软件(官方网站***),它不仅允许用户以交互模式进行数据分析,还支持进行简单的...

    A Little Book of Python for Multivariate Analysis 等 28 本

    A Little Book of Python for Multivariate Analysis.epub Algorithmic Information Theory - Review For Physicists And Natural Scientists.pdf Artificial Inteligence - Leonardo Araujo dos Santos.epub ...

    a little book of r for time series

    本书名为《a little book of r for time series》,由Avril Coghlan编写,是一本关于使用R语言进行时间序列分析的入门书籍。R语言是一种广泛应用于统计计算和图形表示的编程语言。这本书致力于向读者介绍如何使用R...

    The Little Book of Bigger Primes, 2nd Edition, Paulo Ribenboim.pdf

    《The Little Book of Bigger Primes, 2nd Edition》是由Paulo Ribenboim撰写的一本关于素数的数学专著。素数作为数学中的基础概念,是指在大于1的自然数中,除了1和它本身以外不再有其他因数的数。这本书属于数学...

    红宝石小书The Little Book of Ruby

    通过小型独立的示例程序,对Ruby编程进行简单,分步的介绍。

    Little book of sas

    《Little SAS® Book》是Lora D. Delwiche与Susan J. Slaughter共同编著的一本关于SAS软件的入门级教材,该书作为第三版于2003年由SAS Institute Inc.出版,其版权受美国法律保护。本书为读者提供了全面而深入的SAS...

    The Little Book of Python Anti-Patterns

    The Little Book of Python Anti-Patterns

    The Little Black Book of Project Management

    《The Little Black Book of Project Management》由Michael C. Thomsett撰写,该书旨在帮助读者掌握如何有效地管理和完成大型项目。作者通过这本书向读者展示了从项目的初始阶段到最终完成过程中所需的各种技能和...

    little_book_of_semaphore,带目录完全版

    《little_book_of_semaphore,带目录完全版》是一本深入探讨操作系统中同步机制的经典之作,尤其聚焦于信号量这一核心概念。作者Allen B. Downey通过本书,将信号量的基本原理以及在多线程和多进程编程中的应用进行了...

    用R语言处理时间序列 英文版 A Little Book of R for Time Series

    《用R语言处理时间序列》是一本专注于介绍如何使用R语言这一统计软件进行时间序列分析的入门书籍。本书由Avril Coghlan撰写,并由位于英国剑桥的Wellcome Trust Sanger研究所的寄生虫基因组学小组出版。...

    unix操作系统的小知识(Little knowledge of UNIX operating system).doc

    unix操作系统的小知识(Little knowledge of UNIX operating system).doc

    littlefs文件编辑工具浏览器

    《LittleFS文件编辑工具浏览器详解》 在嵌入式开发领域,LittleFS是一款轻量级的文件系统,专为资源有限的微控制器设计。它以其小巧的体积、高效的存储管理和良好的错误恢复机制受到广泛欢迎。然而,对于开发者来说...

Global site tag (gtag.js) - Google Analytics