poj1157LITTLE SHOP OF FLOWERS
Description
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
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的更多相关文章
- Poj-1157-LITTLE SHOP OF FLOWERS
题意为从每行取一瓶花,每瓶花都有自己的审美价值 第 i+1 行取的花位于第 i 行的右下方 求最大审美价值 dp[i][j]:取到第 i 行,第 j 列时所获得的最大审美价值 动态转移方程:dp[i] ...
- sgu 104 Little shop of flowers 解题报告及测试数据
104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...
- [POJ1157]LITTLE SHOP OF FLOWERS
[POJ1157]LITTLE SHOP OF FLOWERS 试题描述 You want to arrange the window of your flower shop in a most pl ...
- 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 ...
- POJ-1157 LITTLE SHOP OF FLOWERS(动态规划)
LITTLE SHOP OF FLOWERS Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19877 Accepted: 91 ...
- 快速切题 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 ...
- 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 ...
- [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 ...
- 【SGU 104】Little shop of flowers
题意 每个花按序号顺序放到窗口,不同窗口可有不同观赏值,所有花都要放上去,求最大观赏值和花的位置. 分析 dp,dp[i][j]表示前i朵花最后一朵在j位置的最大总观赏值. dp[i][j]=max( ...
随机推荐
- .NET 平台下的插件化开发内核(Rabbit Kernel)-转
什么是RabbitHub? RabbitHub 是专门针对 .NET 平台所设计.研发的一套相对完整的插件开发框架,它是由一个内核两大框架多个组件及一系列的开发时支持而构成. RabbitHub 架构 ...
- SQL Server 维护计划实现数据库备份(Step by Step)(转)
SQL Server 维护计划实现数据库备份(Step by Step) 一.前言 SQL Server 备份和还原全攻略,里面包括了通过SSMS操作还原各种备份文件的图形指导,SQL Server ...
- <2016-1-29>
1.打电话,发短信,发邮件 //打电话 <script> function call(){ var call = new CallManage(); call.call('10086'); ...
- EA使用
类逻辑图 关系1:泛化(继承),Driver和Northeastermer继承了Person类 关系2:实现,Northeastermer实现了LivingLeiFeng类 关系3: 关联,两个对象 ...
- Google Developing for Android 三 - Performance最佳实践
Google Developing for Android 三 - Performance最佳实践 发表于 2015-06-07 | 分类于 Android最佳实践 原文 Developing ...
- ./upload/source/class/class_core.php
定义了core这个类 error_reporting(E_ALL); error_reporting() 设置 PHP 的报错级别并返回当前级别.可以参考手册. define('IN_DISCUZ', ...
- 尚学堂Spring视频教程(二):Spring控制反转
用Spring来实现IOC 在上节中我们自定义了一个接口BeanFactory和类ClassPathXmlApplicationContext来模拟Spring,其实它们在Spring中确实是存在的, ...
- 推荐几个最好用的CRM软件,本人亲测
CRM是英文Customer Relationship Management 的简写,一般译作“客户关系管理”.CRM最早产生于美国,由Gartner Group 首先提出的CRM这个概念的.20世纪 ...
- sencha touch百度地图扩展
扩展代码如下: Ext.define('ux.BMap', { alternateClassName: 'bMap', extend: 'Ext.Container', xtype: 'bMap', ...
- qt 工具下的dump工具导出文档出现异常解决方案
今天一直认为qt环境下的dumpcpp 和dumpdoc两个导出工具很好用,可以今天在导出MSChart组件的类方法文档时,虽然导出成功了,但是导出的结果却是令人失望.自己也不知道如何能够正确导出,就 ...