经典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的更多相关文章

  1. sgu 104 Little shop of flowers 解题报告及测试数据

    104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...

  2. 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 ...

  3. SGU 104 Little shop of flowers【DP】

    浪(吃)了一天,水道题冷静冷静.... 题目链接: http://acm.sgu.ru/problem.php?contest=0&problem=104 题意: 给定每朵花放在每个花盆的值, ...

  4. 动态规划(方案还原):SGU 104 Little shop of flowers

    花店橱窗布置问题 时间限制:3000 ms 问题描述(Problem)    假设你想以最美观的方式布置花店的橱窗,你有F束花,每束花的品种都不一样,同时,你至少有同样数量的花瓶,被按顺序摆成一行.花 ...

  5. SGU 104

    104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB PROBLEM Yo ...

  6. 快速切题 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 ...

  7. [POJ1157]LITTLE SHOP OF FLOWERS

    [POJ1157]LITTLE SHOP OF FLOWERS 试题描述 You want to arrange the window of your flower shop in a most pl ...

  8. POJ-1157 LITTLE SHOP OF FLOWERS(动态规划)

    LITTLE SHOP OF FLOWERS Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19877 Accepted: 91 ...

  9. 【SGU 104】Little shop of flowers

    题意 每个花按序号顺序放到窗口,不同窗口可有不同观赏值,所有花都要放上去,求最大观赏值和花的位置. 分析 dp,dp[i][j]表示前i朵花最后一朵在j位置的最大总观赏值. dp[i][j]=max( ...

随机推荐

  1. ios怎样实现快速将显卡中数据读出压缩成视频在cocos2dx扩展开发中

    如果解决ios怎样实现快速将显卡中数据读出压缩成视频在cocos2dx扩展开发中 手机平台性能是个关键问题. 压缩视频分成3个步骤: 读取显卡数据, 使用编码器压缩,保存文件. 使用libav 压缩的 ...

  2. linux提权总结(外文)

    Before starting, I would like to point out - I'm no expert. As far as I know, there isn't a "ma ...

  3. ThinkPHP CURD方法盘点:limit方法

    limit方法也是模型类的连贯操作方法之一,主要用于指定查询和操作的数量,特别在分页查询的时候使用较多.ThinkPHP的limit方法可以兼容所有的数据库驱动类的. 用法 限制结果数量 例如获取满足 ...

  4. C++中的new与delete总结

    1. operator new.operator delete与new.delete操作符的区别: operator new的作用类似于malloc,负责分配内存:operator delete的作用 ...

  5. 把sublime添加到右键菜单(转)

    sublime text是前端利器,为了方便,我们把它加入到win7系统的右键菜单(xp不支持) 保存为bat文件,放入sublimetext安装文件夹与sublime_text同级,双击执行即可. ...

  6. SQL索引详解

    转自:http://www.cnblogs.com/AK2012/archive/2013/01/04/2844283.html SQL索引在数据库优化中占有一个非常大的比例, 一个好的索引的设计,可 ...

  7. chrome浏览器更新到chrome 29.0.1547.76 m,多出一些蛋疼的功能来。

    更新到chrome 29.0.1547.76 m 的时候,莫名其妙多出一些蛋疼的功能来. 1.alert之类的弹出对话框样式变了,并且位置不是居中的,跑到了最上面去了,如下图. 要把这对话框改回原始状 ...

  8. Fast portable non-blocking network programming with Libevent--转

    Learning Libevent Chapter 0: About this document Chapter 1: A tiny introduction to asynchronous IO. ...

  9. volley框架详解

    Volley可是说是把AsyncHttpClient和Universal-Image-Loader的优点集于了一身,既可以像AsyncHttpClient一样非常简单地进行HTTP通信,也可以像Uni ...

  10. Android 100多个Styles快速开发布局XML,一行搞定View属性,一键统一配置UI...

    Android开发中大量使用XML代码作为界面的布局,使用styles能大幅精简XML代码. 比如下面这个界面从AlertDialog至PlacePickerWindow有19个样式相同的跳转Item ...