While some people travel in space from planet to planet and discover new worlds, the others who live on Earth still have to get up in the morning, go to work, return back home and try to have a rest. They don't like this situation anymore and envy people who can afford space travel.
That doesn't suit the government of the Earth. Their goal is to make everyone happy, but that is difficult. That is why the government decided to do some tests in the small town of Lux, and then, if everything goes well, to apply the experience to other cities.
Lux's distinctive feature is that it is situated in a long underground tunnel and there is only one train inside it. Almost everyone in the town uses the train. The government has bought a brainwashing device and installed it in the train. The device is new and its effects aren't well understood yet, so the government decided to limit the number of the spans where the device would be turned on. Statistics on number of passengers travelling between each pair of stations every morning have already been collected. Now the government should pick the spans where the device could be used to make most of the people happy.

Input

The first line contains integers n and k that are the total number of the stations and the number of spans between adjacent stations where the device could be turned on (2 ≤ n ≤ 500; 1 ≤ k ≤ n − 1). The i'th of the next n − 1 lines contains n −i integers. The j'th integer is the number of passengers traveling from i'th to ( ij)'th station. These numbers are non-negative and don't exceed 100. You can assume that every passenger uses the train only once a day.

Output

In the first line output the total number of people who will become happy because of the device. In the second line output k integers in the ascending order that are the indexes of the spans where the device should be turned on. The span between the station i and i + 1 has the index i. If the problem has multiple solutions you can output any of them.

Example

input output
4 1
5 0 6
5 3
5
14
3

思路:先预处理出g[i][j]:表示在边j-1,j上放个洗脑机器时,从去区间[i,j)中出发经过边j-1,j的被洗脑人数。

  dp[i][j]表示前i个点中放了j个洗脑机器,并且边i-1,i上放了洗脑机器时最大的洗脑人数。

 #include <bits/stdc++.h>

 using namespace std;

 #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; int n,s,mx,ls,dp[][],g[][],sum[][],rd[][];
void ptf(int x,int k)
{
if(k>)
ptf(rd[x][k],k-),printf("%d ",x-);
}
int main(void)
{
cin>>n>>s;
for(int i=;i<=n;i++)
for(int j=i+,x;j<=n;j++)
scanf("%d",&g[i][j]),g[i][j]+=g[i][j-];
for(int i=;i<n;i++)
for(int j=i+;j<=n;j++)
for(int k=i;k<j;k++)
sum[i][j]+=g[k][n]-g[k][j-];
memset(dp,-,sizeof(dp));
dp[][]=,mx=-;
for(int i=;i<=n;i++)
for(int j=;j<=s;j++)
for(int k=j;k<i;k++)
if(dp[k][j-]+sum[k][i]>dp[i][j])
dp[i][j]=dp[k][j-]+sum[k][i],rd[i][j]=k;
for(int i=s;i<=n;i++)
if(dp[i][s]>mx)
{
mx=dp[i][s],ls=i;
}
printf("%d\n",mx);
ptf(ls,s);
return ;
}

URAL - 1900 Brainwashing Device的更多相关文章

  1. 1900. Brainwashing Device

    http://acm.timus.ru/problem.aspx?space=1&num=1900 题目大意: 有N个车站,相邻车站之间形成一个段,这样就有N-1个段,每个段最多可以放一个洗脑 ...

  2. URAL1900 Brainwashing Device(dp)

    1900 二维dp挺好推 dp[i][j] = max(dp[i][j],dp[g][j-1]+o[i][i+1]-o[g][i+1])(i>g>=j-1) dp[i][j]表示第i个站台 ...

  3. MonkeyRunner_模拟机_运行脚本

    1.打开创建好的Android模拟机  (使用AVD Manager.exe打开,或者使用cmd窗口 emulator -avd test2打开) 2.打开cmd窗口,输入monkeyrunner,然 ...

  4. ural 1341. Device

    1341. Device Time limit: 1.0 secondMemory limit: 64 MB Major (M): You claimed that your device would ...

  5. ural 2062 Ambitious Experiment

    2062. Ambitious Experiment Time limit: 3.0 secondMemory limit: 128 MB During several decades, scient ...

  6. Linux系统中的Device Mapper学习

    在linux系统中你使用一些命令时(例如nmon.iostat 如下截图所示),有可能会看到一些名字为dm-xx的设备,那么这些设备到底是什么设备呢,跟磁盘有什么关系呢?以前不了解的时候,我也很纳闷. ...

  7. Eclipse调试Android App若选择“Use same device for future launches”就再也无法选择其他设备的问题

    在狂批了某供应商的多媒体控制App有多烂后,夸下海口自己要做一个也是分分钟的事.当然要做好不容易,要超过他们的烂软件还是有信心的.过程中遇到各种坑,其中之一如下 刚开始只使用一个平板进行调试,老是弹出 ...

  8. 设备模型(device-model)之平台总线(bus),驱动(driver),设备(device)

    关于关于驱动设备模型相关概念请参考<Linux Device Drivers>等相关书籍,和内核源码目录...\Documentation\driver-model 简单来说总线(bus) ...

  9. xamarin.forms uwp app部署到手机移动设备进行测试,真机调试(device portal方式部署)

    最近学习xamarin.刚好 手上有一个lumia 930.所以试一试把uwp app部署到手机上,并真机调试一把. 目前环境: 1.开发pc电脑是win10,版本1607.加入了insider,所以 ...

随机推荐

  1. sql 联合查询

    SELECT NZD_Products.Prd_typename a FROM  dbo.NZD_Products where dbo.NZD_Products.Prd_barcodenumber = ...

  2. 【BZOJ】3538: [Usaco2014 Open]Dueling GPS(spfa)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3538 题意不要理解错QAQ,是说当前边(u,v)且u到n的最短距离中包含这条边,那么这条边就不警告. ...

  3. 卡友友刷MPOS注册开通流程!

    1.下载友刷APP:打开微信扫描机器背面二维码—点击右上角游览器打开 2. 注册-身份证认证-结算卡绑定:用本人手机号注册完成后,顺着进行身份认证.以及储蓄结算卡绑定.具体看下图: 3.绑定机器:选择 ...

  4. css横向 弹性盒子布局的一些属性

    <head> <meta charset="utf-8"> <meta name="viewport" content=" ...

  5. win 8升级win8.1的几个问题

        对于习惯了win7来说的小朋友,win8的使用简直有种想砸电脑的冲动啊,特别是玩游戏的小朋友,win8各种bug.对于游戏.咳咳,我只是多说了,我们都是爱学习的好孩子,少玩游戏,少撸.简单说一 ...

  6. 【BZOJ3714】[PA2014]Kuglarz 最小生成树

    [BZOJ3714][PA2014]Kuglarz Description 魔术师的桌子上有n个杯子排成一行,编号为1,2,…,n,其中某些杯子底下藏有一个小球,如果你准确地猜出是哪些杯子,你就可以获 ...

  7. mac下面安装多个JDK

    JDK8 GA之后,小伙伴们喜大普奔,纷纷跃跃欲试,想体验一下Java8的Lambda等新特性,可是目前Java企业级应用的主打版本还是JDK6, JDK7.因此,我需要在我的电脑上同时有JDK8,J ...

  8. webpack 构建项目入门

    参考http://www.cnblogs.com/eyunhua/p/6398885.html ---------------------------------------------------- ...

  9. 160701、理解 Promise 的工作原理

    Javascript 采用回调函数(callback)来处理异步编程.从同步编程到异步回调编程有一个适应的过程,但是如果出现多层回调嵌套,也就是我们常说的厄运的回调金字塔(Pyramid of Doo ...

  10. JavaScript学习笔记-Js操控HTML5 <progress> 标签

    Js操控----HTML5 <progress> 标签 简单模拟下下载进度跑条 <h4>加载进度</h4> <input type="button& ...