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. C语言编写的PHP框架--yaf入门编程

    首先--添加dll,修改php.ini--不同的版本,不同的需求 其次,根据教程http://www.laruence.com/manual/tutorial.firstpage.html#tutor ...

  2. 用dnSpy破解某旅游系统5.2版。

    某系统是网上最常见也是目前最好用的旅游站系统之一,5.1版本之前采用的maxtocode加壳后可以用de4dot反混淆后破解.5.1版本以后用de4dot无法脱壳. 本文仅限学习和讨论,请勿做侵权使用 ...

  3. oralce函数

    1.trunc函数处理数字和日期TRUNC(NUMBER[,DECIMAL]) 数字格式TRUNC(DATE[,FOMAT]) 日期格式2.round函数(四舍五入)ROUND(NUMBER[,DEC ...

  4. requestAnimationFrame 实现JS动画

    requestAnimationFrame会随着浏览器绘制窗口的频率来绘制动画以达到最好的用户体验 // let raf = (function(){ // return window.request ...

  5. Jmeter JDBC执行多条SQL

    今天在编写自动化回归脚本的时候,需要在jmeter的jdbc请求中执行多条sql,在百度里搜索了一些文章,按照网上提供的步骤,发现不起作用,后来发现是作者的截图误导了,为了让后面的同学少走弯路,这里我 ...

  6. AVA 8 :从永久区(PermGen)到元空间(Metaspace)

    你注意到了吗?JDK 8早期可访问版本已经提供下载了,java 开发人员可以使用java 8 提供的新的语言和运行特性来做一些实验.其中一个特性就是完全的移除永久代(Permanent Generat ...

  7. IOS控件:计算文字长度(UITextField,UILabel对象 和 IBAction)

    #import <UIKit/UIKit.h> // UIViewController类为程序提供了基本的视图管理模块 @interface NavControllerViewContro ...

  8. 云计算和SDN中的开源交换机介绍以及使用

    之前关于SDN的开发工作都是在控制器层面上(以ryu为主),现在开始了新的工程项目,需要同时修改控制器和交换机的源码,如果后续项目需要,还可能需要加中间层——网络虚拟层,这部分的知识已经在前面读过了相 ...

  9. 170214、mybatis一级和二级缓存

    mybatis一级缓存是指在内存中开辟一块区域,用来保存用户对数据库的操作信息(sql)和数据库返回的数据,如果下一次用户再执行相同的请求, 那么直接从内存中读数数据而不是从数据库读取. 其中数据的生 ...

  10. 烂笔头-Spring3

    1.spring相关jar包的导入 2.配置文件bean.xml <?xml version="1.0" encoding="UTF-8"?> &l ...