URAL1900 Brainwashing Device(dp)
二维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个站台开放第j次设备 预处理出来通过i-j的人数 包括 i-1~j+1等等的 用o[i][j]表示的
没睡好 %>_<%
因为有可能全部都为0 初始化时dp设为-1.
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<queue>
using namespace std;
#define LL long long
int dp[][],q[];
int w[][],o[][],pa[][];
int main()
{
int i,j,n,k;
cin>>n>>k;
for(i = ; i < n ;i++)
{
for(j = ; j <= n-i ; j++)
{
int x;
cin>>x;
w[i][i+j] = x;
}
}
for(i = ; i <= n ; i++)
{
for(j = n ; j > i ; j--)
o[i][j] = o[i][j+]+w[i][j]+o[i-][j]-o[i-][j+];
}
memset(dp,-,sizeof(dp));
for(i = ; i < n ;i++)
dp[i][] = o[i][i+];
for(j = ; j <= k ; j++)
for(i = j; i < n; i++)
{
int kk;
for(int g = ; g < i ; g++)
{
if(dp[g][j-]+o[i][i+]-o[g][i+]>dp[i][j])
{
dp[i][j] = dp[g][j-]+o[i][i+]-o[g][i+];
kk = g;
}
}
pa[i][j] = kk;
}
int maxz=-,x;
for(i = k; i < n ; i++)
{
if(maxz<dp[i][k])
{
maxz = dp[i][k];
x = i;
}
}
cout<<maxz<<endl;
int e = ;
q[e] = x;
while(k>)
{
x = pa[x][k];
q[++e] = x;
k--;
}
sort(q+,q+e+);
for(i = ; i < e ; i++)
cout<<q[i]<<" ";
cout<<q[e]<<endl;
return ;
}
/*
5 3
5 0 6 5
5 3 7
5 3
10
44
1 2 4
4 2
5 0 6
5 3
5
19
1 2 4 3
5 0 6
5 3
5
24
1 2 3
*/
URAL1900 Brainwashing Device(dp)的更多相关文章
- URAL - 1900 Brainwashing Device
While some people travel in space from planet to planet and discover new worlds, the others who live ...
- 1900. Brainwashing Device
http://acm.timus.ru/problem.aspx?space=1&num=1900 题目大意: 有N个车站,相邻车站之间形成一个段,这样就有N-1个段,每个段最多可以放一个洗脑 ...
- ADIv5.2
ADI:ARM Debug Interface,出到现在共有五代: 1)version1 and version 2:只针对ARM7TDMI和ARM9的processor: 2)version 3:只 ...
- 自动创建字符设备,不需mknod
自动创建设备文件 1.自动创建设备文件的流程 字符设备驱动模块 -->创建一个设备驱动class--->创建属于class的device--->调用mdev工具(自动完成)--> ...
- 构建自己的 Smart Life 私有云(一)-> 破解涂鸦智能插座
博客搬迁至https://blog.wangjiegulu.com RSS订阅:https://blog.wangjiegulu.com/feed.xml 原文链接:https://blog.wang ...
- px、dp与sp的区别以及换算
1.px 即像素,1px代表屏幕上的一个物理像素点. 2.dp dip:device independent pixels(设备独立像素),dp与dip一样,不同的设备有不同的显示效果,一般为了支持W ...
- 【Android学习】android布局中几个距离单位的区别:px、dp、sp
一.px 像素,我们经常说的400*800这种的就是像素,这个比较好理解. 二.dp 要理解dp,首先要先引入dpi这个概念,dpi全称是dots per inch,对角线每英寸的像素点的个数,所以, ...
- 关于dp dip dpi px
在Android开发中,屏幕适配是一件非常让人头疼的事情.有时候在这个机型上调试的漂漂亮亮的UI界面,换一部手机就丑的不忍直视.但为了我们软件更好的用户体验,我们必须适应Android市场上形形色色的 ...
- dp、px、dpi、ppi
概念: dpi(Dots Per Inch):每英寸上的点数,最初用于衡量打印物上每英寸的点数密度,打印机在一英寸内打多少个点.DPI值越小越不精细. ppi(Pixels Per Inch):每英寸 ...
随机推荐
- confusing uv
in a projection u from letf to right is 0---1 in another proj u is the same but when i output u in r ...
- .NET设计模式(10):装饰模式(Decorator Pattern)(转)
概述 在软件系统中,有时候我们会使用继承来扩展对象的功能,但是由于继承为类型引入的静态特质,使得这种扩展方式缺乏灵活性:并且随着子类的增多(扩展功能的增多),各种子类的组合(扩展功能的组合)会导致更多 ...
- RT/Metro商店应用如何如何获取图片的宽高
RT/Metro商店应用如何如何获取图片的宽高 var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms ...
- js中的null VS undefined
var a;------>undefined. JS变量的默认值.注意点在于判断变量的值为null.这是错误的.比如 if( a === null ) { // TODO; }; 实际上是und ...
- IOS Crash捕获
IOS Crash ,就两种情况:一种是异常,另一种是中断[信号量]. #include <libkern/OSAtomic.h> #include <execinfo.h> ...
- eclipse sdk 无法更新
最近祖国越来越强了,强得android开发工具都没法更新了,但是祖国再怎么强也阻挡不了我开发的脚步.下面给大家分享个更新android sdk 的方法.方法原理就是利用国内镜像源. 工具/原料 电脑一 ...
- ubuntu修改ip、网关、dns等
一.使用命令设置Ubuntu IP地址 1.修改配置文件blacklist.conf禁用IPV6 sudo vi /etc/modprobe.d/blacklist.conf 表示用vi编辑器(也可以 ...
- 7 天玩转 ASP.NET MVC — 第 6 天
目录 第 1 天 第 2 天 第 3 天 第 4 天 第 5 天 第 6 天 第 7 天 0. 前言 欢迎来到第六天的 MVC 系列学习中.希望你在阅读此篇文章的时候,已经学习了前五天的内容,这也是第 ...
- 总结 | 如何测试你自己的 RubyGem
如何测试一个Gem gem 开发完了,想要给别人用,那就需要测试啊,测试一个 gem 其实很简单,这里我们用 minitest 为例, rspec 也一样适用.先来看看我们当前这个 gem 的目录结构 ...
- POJ 2513 Colored Sticks (离散化+并查集+欧拉通路)
下面两个写得很清楚了,就不在赘述. http://blog.sina.com.cn/s/blog_5cd4cccf0100apd1.htmlhttp://www.cnblogs.com/lyy2890 ...