LITTLE SHOP OF FLOWERS_DP
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 20802 | Accepted: 9613 |
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 jthnumber 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
【题意】m*n个数,取m个数使加起来的数和最大,但要满足当前这行取得数的列数比前一行取得数的列数大
【思路】dp[i][j]=max(dp[i][j-1],dp[i-1][j-1]+mp[i][j]);
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int N=;
int mp[N][N];
int dp[N][N];
int m,n; int main()
{
while(~scanf("%d%d",&m,&n))
{
memset(dp,,sizeof(dp));
for(int i=;i<=m;i++)
{
for(int j=;j<=n;j++)
{
scanf("%d",&mp[i][j]);
}
}
for(int i=;i<=m;i++)//开始没写,一直wa
dp[i][i]=dp[i-][i-]+mp[i][i];
for(int i=;i<=m;i++)
{
for(int j=i+;j<=n;j++)
{
dp[i][j]=max(dp[i][j-],dp[i-][j-]+mp[i][j]);
}
}
cout<<dp[m][n]<<endl;
}
return ;
}
LITTLE SHOP OF FLOWERS_DP的更多相关文章
- codeforces 632+ E. Thief in a Shop
E. Thief in a Shop time limit per test 5 seconds memory limit per test 512 megabytes input standard ...
- Codeforces632E Thief in a Shop(NTT + 快速幂)
题目 Source http://codeforces.com/contest/632/problem/E Description A thief made his way to a shop. As ...
- poj1157LITTLE SHOP OF FLOWERS
Description You want to arrange the window of your flower shop in a most pleasant way. You have F bu ...
- Magicodes.Shop——版本历史
Magicodes.Shop为湖南心莱信息科技有限公司(xin-lai.com)Magicodes系列产品之一. 产品中引用的Magicodes系列Nuget包的开源库地址为:https://gith ...
- sgu 104 Little shop of flowers 解题报告及测试数据
104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...
- PHP Yii1.1.13(一):命令行创建应用~shop
第一节 初始目录结构 (1)初识目录结构 在创建应用之前,我们来看一下Yii 1.x版本的目录结构:将yii-1.1.13安装文件解压到网站根目录下,打开framework目录,其目录如下图所示 (2 ...
- [POJ1157]LITTLE SHOP OF FLOWERS
[POJ1157]LITTLE SHOP OF FLOWERS 试题描述 You want to arrange the window of your flower shop in a most pl ...
- HDU 4884 TIANKENG’s rice shop (模拟)
TIANKENG's rice shop 题目链接: http://acm.hust.edu.cn/vjudge/contest/123316#problem/J Description TIANKE ...
- HDU 4122 Alice's mooncake shop 单调队列优化dp
Alice's mooncake shop Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...
随机推荐
- Java 集合系列 11 hashmap 和 hashtable 的区别
java 集合系列目录: Java 集合系列 01 总体框架 Java 集合系列 02 Collection架构 Java 集合系列 03 ArrayList详细介绍(源码解析)和使用示例 Java ...
- WebDataTree 使用XML做数据源绑定数据
英文版原文链接:http://www.infragistics.com/help/topic/e5f07b51-ee2d-4a33-aaac-2f43cffff327 所使用的控件版本为:Infrag ...
- SerialPort使用
1.简介随 着USB的流行,串口通讯已经应用到日常生活的很多方面了,USB是一种高速的串口通讯协议,USB接口非常复杂,通常被用在需要传输大量数据数据的地 方,如U盘.相机.打印机等.除了USB这种较 ...
- struts2视频学习笔记 07-08(为Action的属性注入值,指定需要Struts 2处理的请求后缀,常用常量)
课时7 为Action的属性注入值(增加灵活性,适用于经常更改的参数) Struts2为Action中的属性提供了依赖注入功能,在struts2的配置文件中,我们可以很方便地为Action中的属性注入 ...
- ZOJ 3822(求期望)
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- @media用法。
@media版本:CSS2 兼容性:IE5+ 语法: @media sMedia { sRules } 说明: sMedia : 指定设备名称.请参阅附录:设备类型 sR ...
- Oracle11g中ORA-01790
问题源于群里有人问如何让查询的结果值+1,方法其实很简单,直接在SQL语句中+1就可以,如果有空可以用NVL处理. 但是测试的时候我使用了UNION ALL(测试的字段是varchar2类型),结果报 ...
- 为什么 Node.js 这么火,而同样异步模式 Python 框架 Twisted 却十几年一直不温不火?
twisted是一个强大的异步网络框架,应用的面也非常广,但是没有这几年才出现的Node.js火,社区.文档也是很少可怜我觉得二者其实在本质上差不多,而且python使用起来还是比较容易一些的 匿名用 ...
- string字符串类型
一次设置一个key-value 使用set命令可以一次设置一个key-value,使用get命令可以查询key所关联的字符串值.如下图所示. 一次设置多个key-value 使用mset命令可以设置多 ...
- Spring mvc中使用request和response
@ResponseBody @RequestMapping(value="/ip", method=RequestMethod.GET) public String getIP(H ...