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. 【转】Python 第三方 http 库-Requests 学习

    原文地址:http://www.itwhy.org/%E8%BD%AF%E4%BB%B6%E5%B7%A5%E7%A8%8B/python/python-%E7%AC%AC%E4%B8%89%E6%9 ...

  2. ASP.NET控件属性大全

    ASP.NET控件属性大全 DataGridView 控件DataGridView 控件提供用来显示数据的可自定义表.使用 DataGridView 类,可以自定义单元格.行.列和边框. 注意Data ...

  3. 鼠标滑入滑出,输入框获得失去焦点后触发事件的N种方法之一二

    熟悉position的用法 <!doctype html><html lang="en"> <head> <meta charset=&q ...

  4. Python 个人常用汇总

    Python 常用文件操作总结: 导入库路径:sys.path.append('/usr/local/lib/python2.7/site-packages') from random import ...

  5. eclipse新建maven web工程

    每次建maven项目,总会有问题.决定在这整理一次,避免以后浪费时间. 最后目录为 1.首先修改pom.xml 之前老是出现明明改了 java compiler 已maven update 一下就又变 ...

  6. bootstrap 媒体查询

    //各类设备的分辨率 /*超小设备(手机,小于768px)*/ /* Bootstrap 中默认情况下没有媒体查询 */ /*超小型设备(小于768px)*/ @media (min-width:@s ...

  7. 在java中public void与public static void有什么区别 ?

    public void 修饰是非静态方法,该类方法属于对象,在对象初始化(new Object())后才能被调用:public static void 修饰是静态方法,属于类,使用类名.方法名直接调用 ...

  8. angular的过滤器

    angular有一些自带的过滤器,今天我就来写一下. 首先还是先把导入一个angular插件,再在我们的js中把模块和控制台写上(别忘了在html中写入模块名和在body中写入控制台名,当然控制台名可 ...

  9. Pat 1052 Linked List Sorting (25)

    1052. Linked List Sorting (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...

  10. 微信支付 统一订单 $order = WxPayApi::unifiedOrder($input); 断点调试

    定位至 CODE /** * 将xml转为array * @param string $xml * @throws WxPayException */ public static function I ...