洛谷 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 不够 没有取 ...
随机推荐
- android 自己定义标签的使用,实现扁平化UI设计
2014年8月6日11:06:44 android对自己定义标签的使用.实现扁平化UI设计: 1.attrs.xml文件里自己定义标签 如: <?xml version="1.0&qu ...
- angularjs 标签指令
<!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...
- hdu_1166,线段树单点更新
在刷线段树,参考自http://www.notonlysuccess.com/index.php/segment-tree-complete/ #include<iostream> #in ...
- Pocket英语语法---三、英语动词的特点是什么
Pocket英语语法---三.英语动词的特点是什么 一.总结 一句话总结:即表示时间(时态),又表示人数(单复数) 1.第十七讲,不定量表达法? 1.a few为肯定含义几个,few为否定含义没几个, ...
- BZOJ 1251 Splay维护序列
思路: splay维护序列的裸题 啊woc调了一天 感谢yzy大佬的模板-- //By SiriusRen #include <cstdio> #include <cstring&g ...
- 未能加载文件或程序集“MICROSOFT.REPORTVIEWER.WEBFORMS …
此类问题说明没有安装 REPORT .请下载 ReportViewer.msi 安装包. 和sqlsysclrtypes.msi 两个都是对应版本的安装包. 这样再次启动就不会报错了.
- Edge浏览器开发人员工具
UserAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Ch ...
- jsLittle源码封装对象
window.JSLi = ((function(){ var JSLi = function(selector) { return new JSLi.fn.init(selector); }; JS ...
- 运维派 企业面试题2 创建10个 "十个随机字母_test.html" 文件
Linux运维必会的实战编程笔试题(19题) 企业面试题2: 使用for循环在/tmp/www目录下通过随机小写10个字母加固定字符串test批量创建10个html文件,名称例如为: --[root@ ...
- bzoj 2456: mode 思维题 好题
题目描述: 给你一个 $n$ 个数的数列,其中某个数出现了超过 n div 2 次即众数,请你找出那个数.空间大小:1mb 题解:显然,我们是不能开任何数组的,此题专卡空间.然而我们要求的东西也十分简 ...