洛谷 P3486 [POI2009]KON-Ticket Inspector
题目描述
Byteasar works as a ticket inspector in a Byteotian National Railways (BNR) express train that connects Byteburg with Bitwise.
The third stage of the BNR reform (The never ending saga of BNR reforms and the Bitwise hub was presented in the problems Railway from the third stage of XIV Polish OI and Station from the third stage of XV Polish OI. Their knowledge, however, is not required at all in order to solve this problem.) has begun. In particular, the salaries system has already been changed.
For example, to encourage Byteasar and other ticket inspectors to efficient work, their salaries now depend on the number of tickets (passengers) they inspect. Byteasar is able to control all the passengers on the train in the time between two successive stations, but he is not eager to waste his energy in doing so. Eventually he decided he would check the tickets exactly times per ride.
Before setting out, Byteasar is given a detailed summary from which he knows exactly how many passengers will travel from each station to another. Based on that he would like to choose the moments of control in such a way that the number of passengers checked is maximal. Obviously, Byteasar is not paid extra for checking someone multiple times - that would be pointless, and would only disturb the passengers. Write a programme that will determine for Byteasar when he should check the tickets in order to maximise his revenue.
有n个车站,现在有一辆火车从1到n驶过,给出aij代表从i站上车j站下车的人的个数。列车行驶过程中你有K次检票机会,所有当前在车上的人会被检票,问最多能检多少个不同的人的票
输入输出格式
输入格式:
In the first line of the standard input two positive integers and
(
,
) are given. These are separated by a single space and denote, respectively, the number of stations en route and the number of controls Byteasar intends to make. The stations are numbered from
to
in the order of appearance on the route.
In the next lines the summary on passengers is given. The
-th line contains information on the passengers who enter the train on the station
- it is a sequence of  an increasing sequence of integers from the interval from
to
separated by single spaces to the standard output. These numbers should be the numbers of stations upon leaving which Byteasar should control the tickets.
输入输出样例
7 2
2 1 8 2 1 0
3 5 1 0 1
3 1 2 2
3 5 6
3 2
1
2 5
思路:dp
设f[i][j]表示第i次检票在第j车站的最优解。
那么就可以很容易列出状态转移方程:
sum是一个关于上车人数的一维前缀和。
summ是一个关于下车人数的二维前缀和。
f[i][j]=max(f[i][j],f[i-1][l]+sum[j]-sum[l]-tot);(tot=summ[j][j]-summ[l][j])
错因:在计算tot时的式子表示错了。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,k,ans,pre;
int sum[],an[];
int step[][],f[][];
int map[][],summ[][];
int main(){
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++){
for(int j=;j<=i;j++)
summ[i][j]+=summ[i-][j]+summ[i][j-]-summ[i-][j-];
for(int j=i+;j<=n;j++){
scanf("%d",&map[i][j]);
sum[i]+=map[i][j];
summ[i][j]+=map[i][j]+summ[i-][j]+summ[i][j-]-summ[i-][j-];
}
sum[i]+=sum[i-];
}
for(int i=;i<=n;i++)
f[][i]=sum[i]-summ[i][i]-summ[i][]-summ[][i]+summ[][];
for(int i=;i<=k;i++)
for(int j=i;j<=(n-k+i);j++)
for(int l=i-;l<=j-;l++){
int tot=summ[j][j]-summ[l][j];
if(f[i][j]<f[i-][l]+sum[j]-sum[l]-tot){
step[i][j]=l;
f[i][j]=f[i-][l]+sum[j]-sum[l]-tot;
}
}
for(int i=k;i<=n;i++)
if(f[k][i]>ans){ ans=f[k][i];pre=i; }
an[k]=pre;
for(int i=k;i>;i--){
an[i-]=step[i][pre];
pre=step[i][pre];
}
for(int i=;i<=k;i++) cout<<an[i]<<" ";
}
/*
7 2
2 1 8 2 1 0
3 5 1 0 1
3 1 2 2
3 5 6
3 2
1
*/
洛谷 P3486 [POI2009]KON-Ticket Inspector的更多相关文章
- [洛谷P3486]POI2009 KON-Ticket Inspector
问题描述 Byteasar works as a ticket inspector in a Byteotian National Railways (BNR) express train that ...
- 【解题报告】 洛谷 P3492 [POI2009]TAB-Arrays
[解题报告] 洛谷 P3492 [POI2009]TAB-Arrays 这题是我随机跳题的时候跳到的.写完这道题之后,顺便看了一下题解,发现只有一篇题解,所以就在这里顺便写一个解题报告了. 首先当然是 ...
- 洛谷 P3480 [POI2009]KAM-Pebbles
https://www.luogu.org/problemnew/solution/P3480 讲不清楚... 首先对原序列做差分:设原序列为a,差分序列为d 那么,每一次按题意在原序列位置i处取走石 ...
- 洛谷1640 bzoj1854游戏 匈牙利就是又短又快
bzoj炸了,靠离线版题目做了两道(过过样例什么的还是轻松的)但是交不了,正巧洛谷有个"大牛分站",就转回洛谷做题了 水题先行,一道傻逼匈牙利 其实本来的思路是搜索然后发现写出来类 ...
- 洛谷P1352 codevs1380 没有上司的舞会——S.B.S.
没有上司的舞会 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description Ural大学有N个职员,编号为1~N.他们有 ...
- 洛谷P1108 低价购买[DP | LIS方案数]
题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它 ...
- 洛谷 P2701 [USACO5.3]巨大的牛棚Big Barn Label:二维数组前缀和 你够了 这次我用DP
题目背景 (USACO 5.3.4) 题目描述 农夫约翰想要在他的正方形农场上建造一座正方形大牛棚.他讨厌在他的农场中砍树,想找一个能够让他在空旷无树的地方修建牛棚的地方.我们假定,他的农场划分成 N ...
- 洛谷P1710 地铁涨价
P1710 地铁涨价 51通过 339提交 题目提供者洛谷OnlineJudge 标签O2优化云端评测2 难度提高+/省选- 提交 讨论 题解 最新讨论 求教:为什么只有40分 数组大小一定要开够 ...
- 洛谷P1371 NOI元丹
P1371 NOI元丹 71通过 394提交 题目提供者洛谷OnlineJudge 标签云端评测 难度普及/提高- 提交 讨论 题解 最新讨论 我觉得不需要讨论O long long 不够 没有取 ...
随机推荐
- 英语影视台词---四、Sideways
英语影视台词---四.Sideways 一.总结 一句话总结:杯酒人生 Sideways,大致意思是“偏离.倾斜.转向…”.很明显中文译名与英文原名并没有什么关联,<杯酒人生>这个名字,其 ...
- nyoj--46--最少乘法次数(数学+技巧)
最少乘法次数 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 给你一个非零整数,让你求这个数的n次方,每次相乘的结果可以在后面使用,求至少需要多少次乘.如24:2*2=2 ...
- IE(8~11+) 可用右键加速器
必应词典工具 立即安装: 网络安装:http://dict.bing.com.cn/tools_dl.aspx?dl=ie8acc&mkt=ZH-CN 开发示例: <?xml versi ...
- PostgreSQL Replication之第八章 与pgbouncer一起工作(1)
当您在使用大规模的设施工作,可能有时候,您必须处理许多并发打开的连接.没有人会使用十台服务器来为两个并发用户提供服务--在许多情况下,这根本没有意义.大量的设施通常会处理成百上千的并发连接.引入连接池 ...
- PostgreSQL Replication之第五章 设置同步复制(2)
5.2 理解实际影响和性能 在本章中,我们已经讨论了实际影响以及性能影响.但是,有什么好的理论性的例子吗?让我们做一个简单的基准测试,看看复制是怎么做的.我们做这样的测试来为您显示各种耐久性的级别不只 ...
- PostgreSQL Replication之第二章 理解PostgreSQL的事务日志(5)
2.5 XLOG的内部结构 我们将使用事务贯穿本书,并让您在技术层面上更深地洞察事情是如果工作的,我们已经增加了这部分专门处理XLOG的内部工作机制.我们会尽量避免前往下降到C级,因为这将超出本书的范 ...
- html页面颜色名称和颜色值转换
public static string ToHtmlColor(string colorName) { try { if (colorName.StartsWith("#")) ...
- bzoj2763 [JLOI]飞行路线 分层图最短路
问题描述 Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并且航线有一定的 ...
- bzoj1604 牛的邻居 STL
Description 了解奶牛们的人都知道,奶牛喜欢成群结队.观察约翰的N(1≤N≤100000)只奶牛,你会发现她们已经结成了几个“群”.每只奶牛在吃草的时候有一个独一无二的位置坐标Xi,Yi(l ...
- js使用offsetHeight获取div高度为0的问题
今晚试了好久没弄出来,后来获取子一层的div就能获取到高度了 我的情况是这样的:我在最外面写一个<div id="mainBody">, 里面写bootstrap的d ...