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):每英寸 ...
随机推荐
- [百度空间] ld: add library file reference by path & file name
By default, -l option will search libraries with lib* prefix in speficied search paths. i.e. 1 ld -o ...
- WPF使用RoutedCommand自定义命令
主要代码如下所示: /// <summary> /// 声明并定义命令. /// </summary> RoutedCommand ClearCommand = new Rou ...
- UML概述(转载)
UML是一种标准语言,用于指定,可视化,构造和文档的软件系统. UML是OMG在1997年1月提出了创建由对象管理组织(OMG)和UML1.0规范草案. OMG不断努力,使一个真正的行业标准. UML ...
- HDU3341 Lost's revenge(AC自动机&&dp)
一看到ACGT就会想起AC自动机上的dp,这种奇怪的联想可能是源于某道叫DNA什么的题的. 题意,给你很多个长度不大于10的小串,小串最多有50个,然后有一个长度<40的串,然后让你将这个这个长 ...
- codeforces 442C C. Artem and Array(有深度的模拟)
题目 感谢JLGG的指导! 思路: //把数据转换成一条折线,发现有凸有凹 //有凹点,去掉并加上两边的最小值//无凹点,直接加上前(n-2)个的和(升序)//数据太大,要64位//判断凹与否,若一边 ...
- POJ 1969
#include <iostream> #include <cmath> using namespace std; int main() { //freopen("a ...
- shell如何自动输入密码
shell如何自动输入密码 http://linux.ctocio.com.cn/171/12162171.shtml
- IEEE 802.3 Ethernet
Introduction Ethernet 是过去30年以来最为成功的局域网(local area networking)技术. 1. First widely used LAN technology ...
- poj 3114(强连通缩点+SPFA)
题目链接:http://poj.org/problem?id=3114 思路:题目要求很简单,就是求两点之间的花费的最短时间,不过有一个要求:如果这两个city属于同一个国家,则花费时间为0.如何判断 ...
- 李洪强iOS开发之OC[008] -创建一个对象并访问实例变量
// // main.m // 07 - 创建一个对象并且访问实例变量 // // Created by vic fan on 16/7/3. // Copyright © 2016年 李洪强 ...