sgu 104 Little Shop of Flowers
经典dp问题,花店橱窗布置,不再多说,上代码
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#define N 150
#define inf 0x7f7f7f7f
using namespace std; int n, m;
int val[N][N], f[N][N];
int fa[N][N]; void print(int now, int place)
{
if (now == ) printf("%d ", place);
else
{
print(now-, fa[now][place]);
if (now != n) printf("%d ", place);
else printf("%d\n", place);
}
} int main()
{
scanf("%d%d", &n, &m);
memset(val, , sizeof(val));
memset(f, -0x7f, sizeof(f));
for (int i = ; i <= m; ++i) f[][i] = ;
for (int i = ; i <= n; ++i)
for (int j = ; j <= m; ++j)
scanf("%d", &val[i][j]);
for (int i = ; i <= n; ++i)
for (int j = i; j <= m-n+i; ++j)
for (int k = i-; k < j; ++k)
if (f[i][j] < f[i-][k] + val[i][j])
{
f[i][j] = f[i-][k] + val[i][j];
fa[i][j] = k;
}
int ans, place;
ans = -inf;
for (int i = n; i <= m; ++i)
if (ans < f[n][i])
{
ans = f[n][i];
place = i;
}
printf("%d\n", ans);
print(n, place);
}
sgu 104 Little Shop of Flowers的更多相关文章
- sgu 104 Little shop of flowers 解题报告及测试数据
104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...
- 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 ...
- SGU 104 Little shop of flowers【DP】
浪(吃)了一天,水道题冷静冷静.... 题目链接: http://acm.sgu.ru/problem.php?contest=0&problem=104 题意: 给定每朵花放在每个花盆的值, ...
- 动态规划(方案还原):SGU 104 Little shop of flowers
花店橱窗布置问题 时间限制:3000 ms 问题描述(Problem) 假设你想以最美观的方式布置花店的橱窗,你有F束花,每束花的品种都不一样,同时,你至少有同样数量的花瓶,被按顺序摆成一行.花 ...
- SGU 104
104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB PROBLEM Yo ...
- 快速切题 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 ...
- [POJ1157]LITTLE SHOP OF FLOWERS
[POJ1157]LITTLE SHOP OF FLOWERS 试题描述 You want to arrange the window of your flower shop in a most pl ...
- POJ-1157 LITTLE SHOP OF FLOWERS(动态规划)
LITTLE SHOP OF FLOWERS Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19877 Accepted: 91 ...
- 【SGU 104】Little shop of flowers
题意 每个花按序号顺序放到窗口,不同窗口可有不同观赏值,所有花都要放上去,求最大观赏值和花的位置. 分析 dp,dp[i][j]表示前i朵花最后一朵在j位置的最大总观赏值. dp[i][j]=max( ...
随机推荐
- NOTES : A Model of Gas Exchange for Hyperpolarized Xe(129) Magnetic Resonance of the Lung
NOTES : A Model of Gas Exchange for Hyperpolarized Xe(129) Magnetic Resonance of the Lung 背景知识: Ga ...
- 使用hexdump 查看二进制文件
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html 内部邀请码:C8E245J (不写邀请码,没有现金送) 国 ...
- IOS设置button 图片 文字 上下、左右
[btn setImage:imgNor forState:UIControlStateNormal]; [btn setImage:imgSel forState:UIControlStateSel ...
- Files to be needed by importing the android application with eclipse
1. AndroidManifest.xml 2. project.properties # This file is automatically generated by Android Tools ...
- sessionID和cookie
一.cookie机制和session机制的区别***************************************************************************** ...
- OAuth 2 Developers Guide--reference
Introduction This is the user guide for the support for OAuth 2.0. For OAuth 1.0, everything is diff ...
- Win7无线网络共享设置方法
http://jingyan.baidu.com/article/4f34706e89bb2ae387b56d0b.html
- Azure Powershell 创建 Internal Load Balancer
Select-AzureSubscription -SubscriptionName "订阅名称" $serviceName="云服务名称" $ilbName= ...
- 解决myeclipse过期问题
一般myeclise使用期限为30天,超过之后,会频繁的提醒你,购买软件,很讨厌,有个这个小工具,,以后再也不怕啦!!! 使用方法: 1:将这个类导入到myeclipse包中 2:运行main方法,提 ...
- Hive UDAF介绍与开发
UDAF简介 UDAF是用户自定义聚合函数.Hive支持其用户自行开发聚合函数完成业务逻辑. 通俗点说,就是你可能需要做一些特殊的甚至是非常扭曲的逻辑聚合,但是Hive自带的聚合函数不够玩,同时也还找 ...