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 ;
}

最新文章

  1. JDBC Tutorials: Commit or Rollback transaction in finally block
  2. 421. Maximum XOR of Two Numbers in an Array——本质:利用trie数据结构查找
  3. linq to sql (Group By/Having/Count/Sum/Min/Max/Avg操作符)
  4. Remap BMW F11 2010 all ECUs with E-Sys and ENET cable
  5. Android Studio ---------------常用快捷键(更新中。。。。。。)
  6. 利用Navicat实现MySQL数据库结构对比和同步
  7. 【Python灰帽子--黑客与逆向工程师的Python编程之道】我的学习笔记,过程.(持续更新HOT)
  8. 【JAVAEE学习笔记】hibernate01:简介、搭建、配置文件详解、API详解和CRM练习:保存客户
  9. ASP.NET Core 使用Cookie验证身份
  10. 《修改代码的艺术》【PDF】下载
  11. [Sdoi2017]硬币游戏 [高斯消元 KMP]
  12. vue---mixins的用法
  13. 目标检测:YOLO(v1 to v3)——学习笔记
  14. Scala 隐式(implicit)详解
  15. Python程序打包之PyInstaller
  16. ASP.NET Core 登录失败。该登录名来自不受信任的域,不能与集成身份验证一起使用。
  17. 使用Java+Kotlin双语言的LeetCode刷题之路(一)
  18. Database学习 - mysql 数据库 数据操作
  19. 使用sqlalchemy用orm方式写pipeline将scrapy item快速存入 MySQL
  20. SQL Server 请求失败或服务未及时响应。有关详细信息,请参见事件日志或其它适合的错误日志

热门文章

  1. 打开.py文件的方法
  2. vi 的使用,很详细
  3. Unittest框架概念
  4. java必备——经典的Hibernate
  5. Hibernate中持久化类与持久化对象
  6. GS与NGP通信(不断跟新)
  7. BF算法 + KMP算法
  8. 160711、Java 多线程核心技术梳理
  9. 记录--jquery 获取父级、子级、兄弟元素 + 实例
  10. 决策树ID3算法python实现 -- 《机器学习实战》