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: F, V.
  • 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
一道很简单的dp,设f[i][j]表示在第j个花瓶装第i朵花并且前i多已经装过的最大美学价值,be[i][j]为把第i朵花放入第j个花瓶的美学价值。
转移方程:f[i][j]=max(f[i-1][k])+be[i][k];(i<=j<=V,k<j)
即前一朵花在k放转移,且题目里要求花的放置必须按次序。
注意,这道题的初值不能赋0,因为be[i][k]>=-50
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int f[][],be[][];
int main()
{
int ff,v;
while(~scanf("%d%d",&ff,&v))
{
memset(f,-0x3f,sizeof(f));
memset(be,,sizeof(be));
f[][]=;
int ans=-1e4;
for(int i=;i<=ff;i++)
for(int j=;j<=v;j++)
scanf("%d",&be[i][j]);
for(int i=;i<=ff;i++)
for(int j=i;j<=v;j++)
for(int k=;k<j;k++)
f[i][j]=max(f[i][j],f[i-][k]+be[i][j]);
for(int i=;i<=v;i++) ans=max(ans,f[ff][i]);
printf("%d\n",ans);
}
return ;
}

poj1157LITTLE SHOP OF FLOWERS的更多相关文章

  1. Poj-1157-LITTLE SHOP OF FLOWERS

    题意为从每行取一瓶花,每瓶花都有自己的审美价值 第 i+1 行取的花位于第 i 行的右下方 求最大审美价值 dp[i][j]:取到第 i 行,第 j 列时所获得的最大审美价值 动态转移方程:dp[i] ...

  2. sgu 104 Little shop of flowers 解题报告及测试数据

    104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...

  3. [POJ1157]LITTLE SHOP OF FLOWERS

    [POJ1157]LITTLE SHOP OF FLOWERS 试题描述 You want to arrange the window of your flower shop in a most pl ...

  4. SGU 104. Little shop of flowers (DP)

    104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB PROBLEM Yo ...

  5. POJ-1157 LITTLE SHOP OF FLOWERS(动态规划)

    LITTLE SHOP OF FLOWERS Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19877 Accepted: 91 ...

  6. 快速切题 sgu104. Little shop of flowers DP 难度:0

    104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB PROBLEM Yo ...

  7. POJ 1157 LITTLE SHOP OF FLOWERS (超级经典dp,两种解法)

    You want to arrange the window of your flower shop in a most pleasant way. You have F bunches of flo ...

  8. [CH5E02] A Little Shop of Flowers

    问题描述 You want to arrange the window of your flower shop in a most pleasant way. You have F bunches o ...

  9. 【SGU 104】Little shop of flowers

    题意 每个花按序号顺序放到窗口,不同窗口可有不同观赏值,所有花都要放上去,求最大观赏值和花的位置. 分析 dp,dp[i][j]表示前i朵花最后一朵在j位置的最大总观赏值. dp[i][j]=max( ...

随机推荐

  1. mysql connector 和 sqlserver ado.net 的区别

    1,虽然同样是实现了IDataReader接口,但是 对于 MySql.Data.MySqlClient.MySqlDataReader  和 System.Data.SqlClient.SqlDat ...

  2. 通病问题:错误如for architecture arm64: "_OBJC_CLASS_$_CBUUID", referenced from: objc-class-ref in BluetoothLinkOperation.o 类似的问题解决办法

    仔细检查 是否1.相关工程文件未导入2.framework文件未导入3.文件路径缺失 http://www.jianshu.com/p/06ce3a50fa19

  3. Lambda演算 - 简述Y组合子的作用

    Y组合子:\f.(\x.f(xx))(\x.f(xx)),接受一个函数,返回一个高阶函数 Y组合子用于生成匿名递归函数. 什么叫匿名递归函数,考虑以下C语言递归函数 int sum(int n) { ...

  4. LINUX 磁盘如何分区

    fdisk -l  可以查看当前磁盘 假设未分配磁盘为/dev/sdb    size=10G fdisk /dev/sdb  (m for help) 按照提示应该可以分区成功,注意一点   一个磁 ...

  5. Unity3D优化总结

    1.在使用数组或ArrayList对象时应当注意 length=myArray.Length; for(int i=0;i<length;i++) { } 避免 for(int i=0;i< ...

  6. 【解决】若要使用报表生成器,必须在此计算机上安装 .Net Framework 3.5

    在报表库中试图通过点击菜单“在报表生成器中编辑”编辑报表时,会跳转到错误信息页面,提示: 若要使用报表生成器,必须在此计算机上安装 .Net Framework 3.5. 一般情况下并不是因为没有安装 ...

  7. Django RedirectView

    RedirectView作用是重定向一个指定,给定的Url.这个给定的Url可能包含有字典风格的字符串,因为关键字(词)会被改变,所以从这个Url中捕获的参数可能也会被修改,例如,Url中的“%”应该 ...

  8. 查找SQL SERVER被锁的表和解决方法

    查找数据库中被锁表代码: select   request_session_id   spid,OBJECT_NAME(resource_associated_entity_id) tableName ...

  9. 关于ckeditor 第二次加载 出现问题

    在使用ckeditor 出现的问题也比较多的 ,一个问题是图片上传的问题 ,一个就是第二次加载的时候 ckeditor编辑框出现不了的问题 第一个问题 是修改ckeditor js属性 网上都有  第 ...

  10. Sequelize 关系模型简介

    Sequelize 关系模型简介 先介绍一下本文用到的术语: 源: 调用 sequelize 中关系方法的调用者 目标: 调用 sequelize 中关系方法中的参数 比如, User.hasOne( ...