题目描述

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 ![](http://ma

输出格式:

Your programme should print out (in a single line) 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.

输入输出样例

输入样例#1: 复制

7 2
2 1 8 2 1 0
3 5 1 0 1
3 1 2 2
3 5 6
3 2
1
输出样例#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的更多相关文章

  1. [洛谷P3486]POI2009 KON-Ticket Inspector

    问题描述 Byteasar works as a ticket inspector in a Byteotian National Railways (BNR) express train that ...

  2. 【解题报告】 洛谷 P3492 [POI2009]TAB-Arrays

    [解题报告] 洛谷 P3492 [POI2009]TAB-Arrays 这题是我随机跳题的时候跳到的.写完这道题之后,顺便看了一下题解,发现只有一篇题解,所以就在这里顺便写一个解题报告了. 首先当然是 ...

  3. 洛谷 P3480 [POI2009]KAM-Pebbles

    https://www.luogu.org/problemnew/solution/P3480 讲不清楚... 首先对原序列做差分:设原序列为a,差分序列为d 那么,每一次按题意在原序列位置i处取走石 ...

  4. 洛谷1640 bzoj1854游戏 匈牙利就是又短又快

    bzoj炸了,靠离线版题目做了两道(过过样例什么的还是轻松的)但是交不了,正巧洛谷有个"大牛分站",就转回洛谷做题了 水题先行,一道傻逼匈牙利 其实本来的思路是搜索然后发现写出来类 ...

  5. 洛谷P1352 codevs1380 没有上司的舞会——S.B.S.

    没有上司的舞会  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond       题目描述 Description Ural大学有N个职员,编号为1~N.他们有 ...

  6. 洛谷P1108 低价购买[DP | LIS方案数]

    题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它 ...

  7. 洛谷 P2701 [USACO5.3]巨大的牛棚Big Barn Label:二维数组前缀和 你够了 这次我用DP

    题目背景 (USACO 5.3.4) 题目描述 农夫约翰想要在他的正方形农场上建造一座正方形大牛棚.他讨厌在他的农场中砍树,想找一个能够让他在空旷无树的地方修建牛棚的地方.我们假定,他的农场划分成 N ...

  8. 洛谷P1710 地铁涨价

    P1710 地铁涨价 51通过 339提交 题目提供者洛谷OnlineJudge 标签O2优化云端评测2 难度提高+/省选- 提交  讨论  题解 最新讨论 求教:为什么只有40分 数组大小一定要开够 ...

  9. 洛谷P1371 NOI元丹

    P1371 NOI元丹 71通过 394提交 题目提供者洛谷OnlineJudge 标签云端评测 难度普及/提高- 提交  讨论  题解 最新讨论 我觉得不需要讨论O long long 不够 没有取 ...

随机推荐

  1. Linux经常使用命令(九) - cat

    cat命令的用途是连接文件或标准输入并打印.这个命令经常使用来显示文件内容,或者将几个文件连接起来显示,或者从标准输入读取内容并显示,它常与重定向符号配合使用. 1. 命令格式: cat [选项] 文 ...

  2. UVa 10954 Add All 贪心

    贪心   每一次取最小的两个数,注意相加的数也要算' #include<cstring> #include<iostream> #include<cstdio> # ...

  3. 6. MongoDB——Java操作(增删改查)

    转自:https://blog.csdn.net/kai402458953/article/details/79626148 import java.net.UnknownHostException; ...

  4. php7-swoole-Class 'swoole_websocket_server' not found 问题

    标签(空格分隔): php 分析 nginx/apache 读取的php.uini 文件 和 cli模式的php.ini 文件不同导致的 swoole是在cli模式下运行的 或许你安装swoole扩展 ...

  5. java9新特性-9-语法改进:try语句

    1. 使用举例 在java8 之前,我们习惯于这样处理资源的关闭:     java 8 中,可以实现资源的自动关闭,但是要求执行后必须关闭的所有资源必须在try子句中初始化,否则编译不通过.如下例所 ...

  6. HD-ACM算法专攻系列(1)——第几天?

    题目描述: 源码: #include <cstdio> #include <ctime> int main() { int year, month, day; int sum; ...

  7. ListView中嵌套GridView点击事件

    做一个项目时,需要在ListView中嵌套GridView,因为ListView的每个条目中不一定出现GridView,那么问题来了,添加GridView的Item的点击事件后,有GridView出现 ...

  8. python ftp

    #fpt_server.py#__*__ encoding=utf-8 __*__ import socket ,os class MyClass(object): def __init__(self ...

  9. Linux系统启动U盘制作工具

    1.UNetbootin UNetbootin 让你创建 Ubuntu 或者其他 Linux 发行版的可引导 Live U 盘,而无需烧录 CD. 你既能让 UNetbootin 为你下载众多开箱即用 ...

  10. iOS开发——导航栏的一些小设置

    1.导航栏的隐藏与显示:navigationBarHidden - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:YES]; ...