题目大意:把 M 朵花插入 N 个花瓶中,每个花插入不同的花瓶都有一个价值A[Mi][Nj],要使所有的花都插入花瓶,求出来最大的总价值(花瓶为空时价值是0)。

分析:dp[i][j]表示前i朵花插入前j个花瓶的最大价值,那么比较容易看出 dp[i][j] = max(dp[i][j-1], dp[i][j-1]+A[i][j]),也就是这个花瓶要还是不要,别忘记输出路径。

代码如下:

========================================================================================================================================

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int MAXN = ;
const int oo = 1e9+; int dp[MAXN][MAXN];
int A[MAXN][MAXN]; void Path(int x, int y, int M)
{
if(x == )
return ; if(dp[x][y] == dp[x][y-])
Path(x, y-, M);
else
{
Path(x-, y-, M);
printf("%d%c", y, x==M ? '\n':' ');
}
} int main()
{
int M, N;///M朵花,N个花瓶 scanf("%d%d", &M, &N); for(int i=; i<=M; i++)
for(int j=; j<=N; j++)
scanf("%d", &A[i][j]); for(int i=; i<=M; i++)
dp[i][] = -oo; for(int i=; i<=M; i++)
for(int j=; j<=N; j++)
{
dp[i][j] = max(dp[i][j-], dp[i-][j-]+A[i][j]);
} printf("%d\n", dp[M][N]); Path(M, N, M); return ;
}

Little shop of flowers - SGU 104 (DP)的更多相关文章

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

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

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

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

  4. SGU 104

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

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

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

  6. [POJ1157]LITTLE SHOP OF FLOWERS

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

  7. SGU 104 Little shop of flowers【DP】

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

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

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

  9. 【SGU 104】Little shop of flowers

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

随机推荐

  1. 解决Oracle clob字段数据过大问题

    select * from user_lobs where table_name='WX_MAIL';--SYS_LOB0001313121C00015$$ MB FROM user_segments ...

  2. prime,素数的判断——c语言

    输入一个数a,求他是否是素数(用函数) 程序: #include<stdio.h> int prime(int a)-----------------------------------/ ...

  3. 批量缩放PNG图片.

    最近需要缩放N多图片, 找遍了互联网也没有找到方便使用的批量缩放工具.. 趁着周末写一个练手.. #include <iostream> #include <vector> # ...

  4. CSS3中的选择器

    首先, CSS即层叠样式表(Cascading StyleSheet) CSS3是CSS技术的升级版本,CSS3语言开发是朝着模块化发展的 模块包括: 盒子模型.列表模块.超链接方式 .语言模块 .背 ...

  5. [CSS]overflow内容溢出

      定义和用法 overflow 属性规定当内容溢出元素框时发生的事情. 说明 这个属性定义溢出元素内容区的内容会如何处理.如果值为 scroll,不论是否需要,用户代理都会提供一种滚动机制.因此,有 ...

  6. Winbind authentication against active directory

    Winbind authentication against active directory Description This tip will describe how to configure ...

  7. QSslError 类

    QSslError Class Header: #include <QSslError> qmake: QT += network Since: Qt 4.3 注意:这个类中的所有函数都是 ...

  8. Quartz1.8.5例子(九)

    /* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...

  9. Apache与Nginx的比较

    1.Apache与Nginx的优缺点比较 nginx相对于apache的优点: 轻量级 : 同样起web 服务,比apache 占用更少的内存及资源 抗并发 : nginx 处理请求是异步非阻塞的,而 ...

  10. 超实用,你get了吗?再也不怕本地文件更新到环境用Linux命令重启服务器了。。。

    来公司这么久,写过不少代码,可是一碰见关于Linux命令操作的马上绕过,每次都是嚷嚷同事过来帮我替换文件,重启服务器,一直害怕接触命令的我一次一次不嫌麻烦,哈哈.有没有醉了?其实我一直都知道操作不难, ...