【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 ...
随机推荐
- css reset重置样式有那么重要吗?
在以前写html代码的时候,一般都会在head里添加重置样式reset.css,其内容如下: @charset "utf-8"; html, body, div, span, ap ...
- 实战:ADFS3.0单点登录系列-总览
本系列将以一个实际项目为背景,介绍如何使用ADFS3.0实现SSO.其中包括SharePoint,MVC,Exchange等应用程序的SSO集成. 整个系列将会由如下几个部分构成: 实战:ADFS3. ...
- HAXM cannot be installed nutil TV-x is enabled
提示错误:如图 HAXM cannot be installed nutil TV-x is enabled 问题原因: 电脑没有启动Intel的虚拟化技术 解决方法: 重启电脑,进BIOS中启动VT ...
- [教程]Oracle 11g Express 安装和使用教程
使用工具的第一步就是安装工具,配置环境!下面就Oracle 11g Express的安装和简单实用做一简介. 一.下载安装过程 去oracle的官网下载Oracle 11g express,大概300 ...
- C# 与 LUA 的经验对比
1,字符串遍历不同处:例: str = "汉字ABCabc"C#可以使用str[i]取得字符串中的汉字字符和拼音字符:Str[0] :汉Str[1]:字Str[2] : A依次类推 ...
- Windows7+VS2012下OpenGL 4的环境配置
系统环境 Windows 7 Ultimate x64,Visual Studio Ultimate 2012 Update 4,和一块支持OpenGL 4.x的显卡. 准备工作 首先用GPU Cap ...
- 34-php基础:cookie
<?php //1.创建cookie //创建cookie,如下设置,cookie的过期时间为会话结束时 setcookie("name","gaoxiong&qu ...
- matlab如何读取未知行数,带头文件和字段名的txt文件
文件格式是这样的 20120108 50024 X235RZB30801 01 15 2361 2362 2363 2364 2365 2366 2367 2368 2369 236A 236B 23 ...
- [CareerCup] 7.6 The Line Passes the Most Number of Points 经过最多点的直线
7.6 Given a two-dimensional graph with points on it, find a line which passes the most number of poi ...
- 坑死我啊,一个WPF Adorner使用注意事项
1.见鬼了? 项目中遇到这样的要求,一个Button用一个Adorner装饰,这个Adorner上又有一个Button,如下面这样 此时,我们在点击小Button的时候只希望处理小Button的事件, ...