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( ...
随机推荐
- maven dependencies 里面的包怎么导出
进入工程pom.xml 所在的目录下,输入以下命令:mvn dependency:copy-dependencies -DoutputDirectory=lib更简单的 mvn dependency: ...
- php三维数组去重
假设叫数组 $my_array; // 新建一个空的数组. $tmp_array = array(); $new_array = array(); // 1. 循环出所有的行. ( $val 就是某个 ...
- dubbo初识(一)Dubbo架构设计详解
参见http://shiyanjun.cn/archives/325.html Dubbo是Alibaba开源的分布式服务框架,它最大的特点是按照分层的方式来架构,使用这种方式可以使各个层之间解耦合( ...
- 获取Finacial dimension value的description 值
public static Description findDimensionValueDescription(DimensionValue _dimensionValue, Name _dimens ...
- 动手学servlet(六) 过滤器和监听器
过滤器(Filter) 过滤器是在客户端和请求资源之间,起一个过滤的作用,举个例子,比如我们要请求admin文件夹下的index.jsp这个页面,那么我们可以用一个过滤器,判断登录用户是不是管理员 ...
- 关于Jquery中的$.each获取各种返回类型数据的使用方法
var arr = [ "one", "two", "three", "four"]; $.each(arr, func ...
- Smarty模本引擎
封装一个自定义Smarty引擎 Smart模板注释 基本语法:{* 注释内容 *} Smarty模板中的变量 简单变量 四种标量类型:整型.浮点型.布尔型和字符串型! 数组变量 可以给模板分配一个数组 ...
- 在CentOS或RHEL防火墙上开启端口
转载自:https://linux.cn/article-4243-1.html 如果希望在服务器上提供服务,诸如CentOS或RHEL的企业级Linux发行版包含内置的强大防火墙,它们默认的防火墙规 ...
- URL特殊字符的转义
+ 转义符为 %2B 空格 转义符为 + 或 %20 / 转义符为 %2F ? 转义符为 %3F % 转义符为 %25 # 转义符为 %23 & 转义符为 %26 = 转义符为 %3D
- js中的三元运算符
<script type="text/javascript"> var b=5; (b == 5) ? a="true" : a="fal ...