Poj-1157-LITTLE SHOP OF FLOWERS
题意为从每行取一瓶花,每瓶花都有自己的审美价值
第 i+1 行取的花位于第 i 行的右下方
求最大审美价值
dp[i][j]:取到第 i 行,第 j 列时所获得的最大审美价值
动态转移方程:dp[i][j]=max(dp[i-1][j-1]+a[i][j],dp[i][j-1])
代码如下:
#include<stdio.h>
int dp[][];
int a[][];
int Max(int x,int y)
{
return x>y?x:y;
}
int main()
{
int f,v;
while(scanf("%d%d",&f,&v)!=EOF)
{
for(int i=; i<=f; i++)
for(int j=; j<=v; j++)
{
scanf("%d",&a[i][j]);
dp[i][j]=-;
}
dp[][]=a[][];
for(int i=; i<=v; i++) //初始化dp[1][2~v]
dp[][i]=Max(dp[][i-],a[][i]);
for(int i=; i<=f; i++)
for(int j=i; j<=v; j++) //注意从i开始,,上一行的右下方
{
dp[i][j]=Max(dp[i-][j-]+a[i][j],dp[i][j-]);
}
printf("%d\n",dp[f][v]);
}
return ;
}
Poj-1157-LITTLE SHOP OF FLOWERS的更多相关文章
- 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 ...
- sgu 104 Little shop of flowers 解题报告及测试数据
104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...
- [POJ1157]LITTLE SHOP OF FLOWERS
[POJ1157]LITTLE SHOP OF FLOWERS 试题描述 You want to arrange the window of your flower shop in a most pl ...
- 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 ...
- POJ-1157 LITTLE SHOP OF FLOWERS(动态规划)
LITTLE SHOP OF FLOWERS Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19877 Accepted: 91 ...
- 快速切题 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 ...
- poj1157LITTLE SHOP OF FLOWERS
Description You want to arrange the window of your flower shop in a most pleasant way. You have F bu ...
- POJ1157 LITTLE SHOP OF FLOWERS DP
题目 http://poj.org/problem?id=1157 题目大意 有f个花,k个瓶子,每一个花放每一个瓶子都有一个特定的美学值,问美学值最大是多少.注意,i号花不能出如今某大于i号花后面. ...
- [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 ...
- 【POJ - 3262】Protecting the Flowers(贪心)
Protecting the Flowers 直接中文 Descriptions FJ去砍树,然后和平时一样留了 N (2 ≤ N ≤ 100,000)头牛吃草.当他回来的时候,他发现奶牛们正在津津有 ...
随机推荐
- APP测试点总结
1.功能性测试: ——根据产品需求文档编写测试用例. ——软件设计文档编写用例. 注意:就是根据产品需求文档编写测试用例而进行测试.2.兼容性测试: ——android版本的兼容性 ——手机分辨率兼容 ...
- python-appium识别元素等待时间
1.显式等待 一个显式等待是你定义的一段代码,用于等待某个条件发生然后再继续执行后续代码. from selenium import webdriverfrom selenium.webdriver. ...
- 纸上谈兵:左倾堆(leftist heap)
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 我们之前讲解了堆(heap)的概念.堆是一个优先队列.每次从堆中取出的元素都是堆中 ...
- 第一波实习的前端笔记(2)——js.md
1.如何解决移动端点透问题? $('xx').on('touchend', function(event){ event.preventDefault(); }) 但是,存在滑动页面会触发问题.期待更 ...
- 常用vim设置
set tabstop=4set shiftwidth=4set expandtabset hlsearchset cindent set autoindent set tabstop=4是设TAB宽 ...
- A Beginner's Guide To Understanding Convolutional Neural Networks(转)
A Beginner's Guide To Understanding Convolutional Neural Networks Introduction Convolutional neural ...
- ajax分页
html显示 <center> <div id="fyh"> <ul class="pagination" id="fy ...
- 样式link属性media用法--媒体类型查询
引用外部样式使用link 你可能想针对将要显示页面的设备类型(桌面PC.笔记本电脑.平板电脑.手机或者甚至页面的印刷版本)来调整页面的样式,可以利用一个media属性, 在<link>元素 ...
- 获取ServletContext
ServletConfig config.getServletContext(): GenericServlet this.getServletContext(); HttpSe ...
- 定位frame 中的对象
在web 应用中经常会出现frame 嵌套的应用,假设页面上有A.B 两个frame,其中B 在A 内,那么定位B 中的内容则需要先到A,然后再到B.switch_to_frame 方法可以把当前定位 ...