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( ...
随机推荐
- linux提权总结(外文)
Before starting, I would like to point out - I'm no expert. As far as I know, there isn't a "ma ...
- JFinal的Shiro权限管理插件--玛雅牛 / JFinalShiro
http://git.oschina.net/myaniu/jfinalshiroplugin JFinalShiroPlugin JFinal的Shiro插件,实现权限管理. 升级说明 1)支持JF ...
- 使用百度地图结合GPS进行定位
本文在上文基础上加入GPS定位功能,实现实时定位,代码如下: Activity: package com.home; import android.app.Activity; import andro ...
- 01---HTML整理
1.前端: 不同设备的适配 显示-->性能优化 某些计算任务 html5 2.xml: 传输数据 保存配置文件 3.乱码是 ...
- springMVC整合xStream
一. 简单介绍: xStream能够轻易的将Java对象转换成xml.JSON.本篇博客将使用springMVC整合利用xStream转换xml. 关于xStream使用的博文:http://blog ...
- Retina屏下1px border
layout tltle tags post ios7下移动web开发的几个坑 webapp 1.Retina屏下1px border 由于高清屏的特性,1px是由2×2个像素点来渲染,那么我们样式上 ...
- [013]函数重载--int*和void*的匹配优先级
同事去面试的时候的问题: 测试一下发现:在同时存在int*和void*的重载函数时,vs2010的环境下,优先匹配void* #include<iostream> using namesp ...
- [置顶] 博客已迁移至ryantang.me
大家好,感谢大家一直以来的支持,本博客内容已停止更新,新内容将发布到我的新博客,地址是:ryantang.me,欢迎大家继续支持,我会在ryantang.me上发布内容更丰富的文章内容,谢谢! Rya ...
- AT-FragmentPagerAdapter
关于FragmentPagerAdapter的粗略翻译 英文版api地址:FragmentPagerAdapter(自备梯子) FragmentPagerAdapter 类概述(Class Ov ...
- 使用angular的ng-repeat遇到的一个问题
问题描述:ng-repeat绑定的数据集动态更新之后其包裹的子元素所绑定的事件全部丢失:问题详述:问题代码如下: <style> img{width:100px;height:100px; ...