Narrow Art Gallery
| Time Limit: 4000ms, Special Time Limit:10000ms, Memory Limit:65536KB |
| Total submit users: 11, Accepted users: 9 |
| Problem 13240 : No special judgement |
| Problem description |
|
A long art gallery has 2N rooms. The gallery is laid out as N rows of 2 rooms side-by-side. Doors connect all adjacent rooms (north-south and east-west, but not diagonally). The curator has been told that she must close off k of the rooms because of staffing |
| Input |
|
Input will consist of multiple problem instances (galleries). Each problem instance will begin with a line containing two integers N and k, where 3 ≤ N ≤ 200 gives the number of rows, and 0 ≤ k ≤ N gives the number of rooms that must be closed off. This |
| Output |
|
For each gallery, output the amount of value that the general public may optimally receive, one line per gallery. |
| Sample Input |
6 4 |
| Sample Output |
17 |
| Problem Source |
| ACM-ICPC North America Qualifier 2014 |
我还是非常弱的……
dp[i][j][k]:前i行在状态j时,关掉k个房间后的最大值
当然有些k在某些状态时是訪问不到的,所以此时赋上一个非常小的值。这样就不影响结果
j是有3个状态。0为i行两个都取不到。1为关掉i行左边那个房间,2为关掉i行右边那个房间
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<list>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
int dp[210][3][210],k,n,g[210][2];
int work()
{
for(int i=0;i<3;i++)
fill(dp[0][i],dp[0][i]+k+1,INT_MIN);
dp[0][0][0]=g[0][0]+g[0][1];
dp[0][1][1]=g[0][1];
dp[0][2][1]=g[0][0];
for(int i=1;i<n;i++)
for(int j=0;j<=k;j++)
{
dp[i][0][j]=max(dp[i-1][0][j],max(dp[i-1][1][j],dp[i-1][2][j]))+g[i][0]+g[i][1];
if(j==0)
dp[i][1][j]=dp[i][2][j]=INT_MIN;
else
{
dp[i][1][j]=max(dp[i-1][0][j-1],dp[i-1][1][j-1])+g[i][1];
dp[i][2][j]=max(dp[i-1][0][j-1],dp[i-1][2][j-1])+g[i][0];
}
}
return max(dp[n-1][0][k],max(dp[n-1][1][k],dp[n-1][2][k]));
}
int main()
{
while(cin>>n>>k)
{
if(n==0&&k==0)
break;
for(int i=0;i<n;i++)
for(int j=0;j<2;j++)
cin>>g[i][j];
cout<<work()<<endl;
}
}
Narrow Art Gallery的更多相关文章
- poj 1279 -- Art Gallery (半平面交)
鏈接:http://poj.org/problem?id=1279 Art Gallery Time Limit: 1000MS Memory Limit: 10000K Total Submis ...
- poj 1279 Art Gallery - 求多边形核的面积
/* poj 1279 Art Gallery - 求多边形核的面积 */ #include<stdio.h> #include<math.h> #include <al ...
- 【POJ】【2068】Art Gallery
计算几何/半平面交 裸的半平面交,关于半平面交的入门请看神犇博客:http://blog.csdn.net/accry/article/details/6070621 然而代码我是抄的proverbs ...
- 再来一道测半平面交模板题 Poj1279 Art Gallery
地址:http://poj.org/problem?id=1279 题目: Art Gallery Time Limit: 1000MS Memory Limit: 10000K Total Su ...
- poj 1279 Art Gallery (Half Plane Intersection)
1279 -- Art Gallery 还是半平面交的问题,要求求出多边形中可以观察到多边形所有边的位置区域的面积.其实就是把每一条边看作有向直线然后套用半平面交.这题在输入的时候应该用多边形的有向面 ...
- UVA 10078 The Art Gallery
Problem: Century Arts has hundreds of art galleries scattered all around the country and you are hir ...
- 【POJ 1279】Art Gallery
http://poj.org/problem?id=1279 裸的半平面交的模板,按极角排序后维护一个双端队列,不要忘了最后要去除冗余,即最后一条边(或者更多的边)一定在双端队列里,但它不一定构成半平 ...
- POJ 1279 Art Gallery(半平面交)
题目链接 回忆了一下,半平面交,整理了一下模版. #include <cstdio> #include <cstring> #include <string> #i ...
- 【POJ】1279 Art Gallery
http://poj.org/problem?id=1279 题意:给一个n个点的多边形,n<=1500,求在多边形内能看到所有多边形上的点的面积. #include <cstdio> ...
随机推荐
- 企业级分布式监控系统--zabbix
目录 1.Zabbix简介 2.zabbix安装 3.工作原理 4.监控功能 5.监控系统架构 6.Zabbix系统架构 7.Zabbix组件构成 8.zabbix监控环境中基本概念 正文 回到顶部 ...
- 前端性能优化---DOM操作
小结 1缓存DOM对象 场景:缓存DOM对象的方式也经常被用在元素的查找中,查找元素应该是DOM操作中最频繁的操作了,其效率优化也是大头.在一般情况下,我们会根据需要,将一些频繁被查找的元素缓存起来, ...
- MyEclipse创建SSH项目(Java web由maven管理)
JavaEE后台开发,MyEclipse创建SSH项目,MyEclipse创建Java web 由maven管理的SSH项目. Demo工程源码github地址 1.创建SSH项目 1.创建web工程 ...
- java中负数的补码转换为十进制
一个数如果为正,则它的原码.反码.补码相同:一个正数的补码,将其转化为十进制,可以直接转换. 已知一个负数的补码,将其转换为十进制数,步骤: 1.先对各位取反: 2.将其转换为十进制数: 3.加上负号 ...
- html 表单赋值 和 时间戳 转换
<script> window.onload = function () { var str; // console.log(@ViewBag.ID); $.post("/Ser ...
- h5调用app中写好的的方法
做h5页面的时候,总会遇到些不能解决的问题于是就要与app做一些交互, app那边编辑好的方法后我们怎么用js语法去调用app编写好的方法 if(this.$winInfo.shebei == 1){ ...
- WPF动态折线图
此项目源码下载地址:https://github.com/lizhiqiang0204/WpfDynamicChart 效果图如下: 此项目把折线图制作成了一个控件,在主界面设置好参数直接调用即可,下 ...
- MySQL在Linux下的表名如何不区分大小写
MySQL在Linux下的表名如何不区分大小写 今天测试的时候,遇到一些问题,明明看到数据,就是查不出来;后来发现,在linux下, mysql的表名区分大小写,而在windows下是不区分,从w ...
- 【Android】进程间通信IPC——AIDL
AIDL官网定义AIDL(Android 接口定义语言)与您可能使用过的其他 IDL 类似. 您可以利用它定义客户端与服务使用进程间通信 (IPC) 进行相互通信时都认可的编程接口. 在 Androi ...
- day007 列表类型、元祖类型、 字典类型、 集合类型的内置方法
目录 列表数据类型的内置方法 作用 定义方式 优先掌握的方法 需要掌握的方法 元祖类型的内置方法 作用 定义方式 优先掌握的方法(参考列表方法) 字典类型的内置方法 作用 定义方式 优先掌握的方法 需 ...
