【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 ...
随机推荐
- RabbitMQ 一二事(4) - 路由模式介绍
路由模式其实和订阅模式差不多,只不过交换机的类型不同而已 路由模式可以用下图来表示,比订阅模式多了一个key,举个栗子就是根据不同的人群来订阅公众号,来收取消息 根据不同的key来获取不同的消息 最简 ...
- 3D跑酷遇到的问题
前言 项目名称:3D跑酷项目 写作目地:使用Asset Server进行多人协作开发过程中,记录遇到的问题 问题1:UIAtlas无法自动更新 描述:NGUI的Atlas图集(图片)无法自动更新 后果 ...
- HBuilder打包ios应用
1先安装itunes在电脑上 2,在HBuilder的工具栏上的"工具"选项卡上安装ios插件
- Java NIO 概述
Channel 和 Buffer 标准的Java IO编程接口是面向字节流和字符流的 而 NIO 是面向通道和缓冲区的 数据总是从通道中读到Buffer中,或者从Buffer写入通道中 NIO可以理解 ...
- Linux下用信号量实现对共享内存的访问保护
转自:http://www.cppblog.com/zjl-1026-2001/archive/2010/03/03/108768.html 最近一直在研究多进程间通过共享内存来实现通信的事情,以便高 ...
- Linux Linux程序练习七
题目:实现两个程序mysignal.mycontrl,mycontrl给mysignal发送SIGINT信号,控制mysignal是否在屏幕打印“hello”字符串. //捕捉信号 #include ...
- 一款漂亮实用的Android开源日期控件timessquare
这个开源控件可以兼容到SDK8版本,可以自定义显示的年月日,以及时间范围,如图 如果我们只想显示两个月的日期选择区间: final Calendar month = Calendar.getInsta ...
- findstr()与strfind()的区别
matlab中这两个字符串查找的函数findstr(), strfind()表明上看起来用法相似,效果也相似. 1. findstr(s1,s2)--在较长的字符串中查找较短的字符串出现的次数,并返回 ...
- 【转载】UVa 11464 Even Parity 偶数矩阵
题意:给你一个n*n的01矩阵,让你把这个矩阵中尽量少的0转换成1,使得矩阵每个位置的上下左右四个相邻的数加起来能被2整除,求最少的转换数 首先,n 的规模并不大,最大只有15.但是完全枚举整个矩阵显 ...
- Jenkins进阶系列之——09配置Linux系统ssh免密码登陆
ssh认证的完整描述:https://www.ibm.com/developerworks/cn/linux/security/openssh/part1/ 说明:点我去查看 今天我们只说生成ssh的 ...