【SGU 104】Little shop of flowers
题意
每个花按序号顺序放到窗口,不同窗口可有不同观赏值,所有花都要放上去,求最大观赏值和花的位置。
分析
dp,dp[i][j]表示前i朵花最后一朵在j位置的最大总观赏值。
dp[i][j]=max(dp[i-1][k]+f[i][j])
代码
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=;
int n,w,ans=-;
int dp[N][N],f[N][N],last[N][N],ansp[N];
int main()
{ scanf("%d%d",&n,&w);
for(int i=; i<=n; i++)
{
for(int j=; j<=w; j++)
{
scanf("%d",&f[i][j]);
}
}
for(int i=; i<=n; i++)
{
for(int j=i; j<=w-n+i; j++)
{
dp[i][j]=dp[i-][i-]+f[i][i];
for(int k=i-; k<j; k++)
{
if(dp[i-][k]+f[i][j]>dp[i][j])
{
dp[i][j]=dp[i-][k]+f[i][j];
last[i][j]=k;
}
}
if(i==n && dp[n][j]>ans)
{
ans=dp[n][j];
ansp[n]=j;
}
}
}
int k=ansp[n];
for(int i=n; i>; i--)
{
k=last[i][k];
ansp[i-]=k;
}
printf("%d\n",ans);
for(int i=; i<=n; i++)
printf("%d ",ansp[i]);
return ;
}
【SGU 104】Little shop of flowers的更多相关文章
- 题解 【POJ1157】LITTLE SHOP OF FLOWERS
先把题目意思说一下: 你有F束花,编号为\(1\)~\(F\)(\(1<=F<=100\)),\(V\)个花瓶,编号为\(1\) ~\(V\)(\(1<=V<=100\)), ...
- 【SGU 390】Tickets (数位DP)
Tickets Description Conductor is quite a boring profession, as all you have to do is just to sell ...
- 【CodeForces 621C】Wet Shark and Flowers
题 There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such tha ...
- 【UOJ #104】【APIO 2014】Split the sequence
http://uoj.ac/problem/104 此题的重点是答案只与切割的最终形态有关,与切割顺序无关. 设\(f(i,j)\)表示前\(i\)个元素切成\(j\)个能产生的最大贡献. \(f(i ...
- 【SPOJ 104】HIGH - Highways (高斯消元)
题目描述 In some countries building highways takes a lot of time- Maybe that's because there are many po ...
- 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 ...
- 【81.82%】【codeforces 740B】Alyona and flowers
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【Codeforces 258E】 Devu and Flowers
[题目链接] http://codeforces.com/contest/451/problem/E [算法] 容斥原理 [代码] #include<bits/stdc++.h> usin ...
随机推荐
- poj 1463 Strategic game DP
题目地址:http://poj.org/problem?id=1463 题目: Strategic game Time Limit: 2000MS Memory Limit: 10000K Tot ...
- Ajax读取文件时出现的缓存问题
对于Ajax缓存问题时,由于浏览器的版本问题,有时候当服务器端已更改文件中的内容,而客户端并得不到更新后的文件,而是延续之前的文件内容,解决办法是:在读取的文件内容后加一串的地址:JSON的格式为[{ ...
- smarty模板继承
- 17Mybatis_动态sql-sql片段
这篇文章讲一下sql片段. 讲一下sql片段的的需求: 将上边实现的动态sql判断代码块抽取出来,组成一个sql片段.其它的statement中就可以引用sql片段. 方便程序员进行开发. 第一步我们 ...
- PHP通用函数 - 日期生成时间轴
/** * 时间轴函数, Unix 时间戳 * @param int $time 时间 */ function TranTime($time) { //$time = strtotime($time) ...
- js 中常用的方法
1..call() 将.call()点之前的属性或方法,继承给括号中的对象. 2.(function(){xxx})() 解释:包围函数(function(){})的第一对括号向脚本返回未命名的函数, ...
- windows 7 和 Ubuntu的双系统安全删除Ubuntu
1,准备文件 百度云盘链接:http://pan.baidu.com/s/1kVxuwSn 密码:e8ma 2,操作流程 #1,进入win7,将第一步下载的文件放在C:\windows\system3 ...
- Android 6.0 SDK 找不到HttpClient的解决方法
一.情况描述 在eclipse或Android Studio开发时(笔者目前只用过Android Studio),设置Android SDK的编译版本为23时,且使用了httpClient相关类的库项 ...
- [CareerCup] 7.4 Implement Multiply Subtract and Divide 实现乘法减法和除法
7.4 Write methods to implement the multiply, subtract, and divide operations for integers. Use only ...
- LeetCode 笔记21 生成第k个排列
题目是这样的: The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all ...