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( ...
随机推荐
- ADXL3xx: 读取 ADXL3xx 加速度传感器
原文链接:https://www.arduino.cc/en/Tutorial/ADXL3xx ADXL3xx加速度传感器 本教程将为你展示如何读取Analog Devices的ADXL3xx系列加速 ...
- Linux disk_partition_dev_马士兵_note
一般装Linux会遇到的问题: 找不到硬件驱动 现在主流的一些硬件 不支持Linux驱动 尽量找主流的硬件,尽量找老一点的硬件 装系统: 1.记下 系统 ---->到时候要找驱动 2 ...
- 从jquery源码中看类型判断和数组的一些操作
在深入看jquery源码中,大家会发现源码写的相当巧妙.那我今天也通过几个源码中用到的技巧来抛砖引玉,希望大家能共同研究源码之精华,不要囫囵吞枣. 1.将类数组转化成数组 我想大家首先想到的方法是fo ...
- 转ASP.NET1.1请求队列限制
在教务web的选课的维护中,经常面临asp.net1.1报错,在客户端跳转到用户自定义页面,在服务器端可以看到如下错误信息: “/”应用程序中的服务器错误. 服务器太忙 说明: 执行当前 Web 请求 ...
- Win8.1安装Visual Studio 2015提示需要KB2999226
http://www.microsoft.com/zh-cn/download/details.aspx?id=48234 ,下载解压出来就有了,里面包含Vista.Win7.Win8.1三个系统x8 ...
- petapoco存储过程
db.ExecuteScalar<string>("exec P_GetCode @0,@1,@2,@3,@4,@5",); using (var db = new D ...
- Android Studio 修改字体
修改字体(font)大小(size) 本文引用: http://blog.csdn.net/caroline_wendy/article/details/21876727 Android St ...
- Effective objective-c 2.0阅读笔记
这本书非常的好,看完后,感触挺深,总结纪录一下,针对ios开发的备忘: 注:分类和原著有些不同,自己总结学习用的,仅供参考. 系统篇: 了解oc起源:继承c,由Smalltalk演化而来.动态语言 ...
- 初探VIM编辑器
初探VIM 引言---什么是Vim? 接触Linux这么久,想必对于一切皆文件的哲学思想已经不陌生了.因此,学习并掌握用一款Linux文本编辑器,对于玩转LInux来说,是很有必要的. vi编辑器是U ...
- Unity已经学会的
1.以MonoBehaviour为脚本的开发模式. 2.MonoBehaviour的大多数API. 3.动画系统大多数了解. 4.UI了解一些,能写UI. 5.Editor了解一些,能写Editor. ...