先把题目意思说一下:

你有F束花,编号为\(1\)~\(F\)(\(1<=F<=100\)),\(V\)个花瓶,编号为\(1\) ~\(V\)(\(1<=V<=100\)),

一束花只能放到一个花瓶里,一个花瓶只能放一束花,并且花必须按编号放入花瓶,

即若编号为\(a\)的花放到编号为\(b\)的花瓶里,那么编号为\(a+1\) ~\(F\)的花只能放在编号为\(b+1\) ~\(V\)的花瓶里,

并且,第\(i\)束花放到第\(j\)个花瓶有一个美丽值\(a_{i,j}\)(\(-50<=a_{i,j}<=50\)),求将所有花放入花瓶的最大的美丽值.

解析

这题其实就和背包一样...

我们设\(f[i][j]\)表示将前\(i\)束花放入前\(j\)个花瓶里的最大美丽值,

那么考虑状态转移,

对于当前枚举到的\(i\),\(j\),

要么把\(i\)放入\(j\)中,即\(f[i][j]=f[i-1][j-1]+a[i][j]\),

要么就不放,即\(f[i][j]=f[i][j-1]\),

所以,两重循环扫一遍就行了(是不是感觉好简单)

上代码吧:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; inline int read(){
int sum=0,f=1;char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0' && ch<='9'){sum=sum*10+ch-'0';ch=getchar();}
return f*sum;
} int n,m;
int a[1001][1001];
int f[1001][1001]; int main(){
n=read();m=read();
memset(f,-0x3f,sizeof(f));
for(int i=0;i<=m;i++) f[0][i]=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++) a[i][j]=read();
for(int i=1;i<=n;i++){
for(int j=i;j<=m;j++) f[i][j]=max(f[i][j-1],f[i-1][j-1]+a[i][j]);
}
printf("%d\n",f[n][m]);
return 0;
}

题解 【POJ1157】LITTLE SHOP OF FLOWERS的更多相关文章

  1. [POJ1157]LITTLE SHOP OF FLOWERS

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

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

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

  3. POJ1157 LITTLE SHOP OF FLOWERS DP

    题目 http://poj.org/problem?id=1157 题目大意 有f个花,k个瓶子,每一个花放每一个瓶子都有一个特定的美学值,问美学值最大是多少.注意,i号花不能出如今某大于i号花后面. ...

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

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

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

  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. poj1157LITTLE SHOP OF FLOWERS

    Description You want to arrange the window of your flower shop in a most pleasant way. You have F bu ...

  8. POJ 1157 LITTLE SHOP OF FLOWERS (超级经典dp,两种解法)

    You want to arrange the window of your flower shop in a most pleasant way. You have F bunches of flo ...

  9. [CH5E02] A Little Shop of Flowers

    问题描述 You want to arrange the window of your flower shop in a most pleasant way. You have F bunches o ...

随机推荐

  1. 【Python】【demo实验32】【回文数的确认】

    原题: 我的代码: #!/usr/bin/python # encoding=utf-8 # -*- coding: UTF-8 -*- #判断一个数字是否为回文数 即 12345654321 x = ...

  2. getBoundingClientRect()方法

    是在<javascript高级程序设计>中看到了这个方法.getBoundingClientRect在IE5中就有,但似乎不怎么引起我们注意. 返回值:它返回一个clientRect对象, ...

  3. 用三台虚拟机搭建Hadoop全分布集群

    用三台虚拟机搭建Hadoop全分布集群 所有的软件都装在/home/software下 虚拟机系统:centos6.5 jdk版本:1.8.0_181 zookeeper版本:3.4.7 hadoop ...

  4. mysql5.6 Centos6.6安装

    1.检查防火墙 是否关闭service iptables status service iptables stopchkconfig iptables off 2. SELINUXvim /etc/s ...

  5. GCD和LCM

    GCD _ LCM 是给你两个数A B 的最大公约数, 以及最小公倍数 the greatest common divisor and the least common multiply ! 最大公约 ...

  6. exclipe怎么设置编码为UTF-8

    如果要使插件开发应用能有更好的国际化支持,能够最大程度的支持中文输出,则最好使 Java文件使用UTF-8编码.然而,Eclipse工作空间(workspace)的缺省字符编码是操作系统缺省的编码,简 ...

  7. 【强化学习】MOVE37-Introduction(导论)/马尔科夫链/马尔科夫决策过程

    写在前面的话:从今日起,我会边跟着硅谷大牛Siraj的MOVE 37系列课程学习Reinforcement Learning(强化学习算法),边更新这个系列.课程包含视频和文字,课堂笔记会按视频为单位 ...

  8. vue-cli实现原理

    分析:https://kuangpf.com/vue-cli-analysis/create/basic-verification.html vue-cli-service :https://blog ...

  9. 封装一些简单的 dom 操作

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  10. 完美解决Uncaught SyntaxError: Unexpected end of input

    Unexpected end of input  的英文意思是“意外的终止输入” 他通常表示我们浏览器在读取我们的js代码时,碰到了不可预知的错误,导致浏览器 无语进行下面的读取 通常造成这种错误的原 ...