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
cuts. Visitors must be able to enter using at least one of the two rooms at one end of the gallery, proceed through the gallery, and exit from at least one of the two rooms at the other end. Therefore, the curator must not close off any two rooms that would
block passage through the gallery. That is, the curator may not block off two rooms in the same row or two rooms in adjacent rows that touch diagonally. Furthermore, she has determined how much value each room has to the general public, and now she wants to
close off those k rooms that leave the most value available to the public, without blocking passage through the gallery.



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
is followed by N rows of two integers, giving the values of the two rooms in that row. Each room’s value v satisfies 0 ≤ v ≤ 100. A line containing 0 0 will follow the last gallery.

Output

For each gallery, output the amount of value that the general public may optimally receive, one line per gallery.

Sample Input
6 4
3 1
2 1
1 2
1 3
3 3
0 0 4 3
3 4
1 1
1 1
5 6 10 5
7 8
4 9
3 7
5 9
7 2
10 3
0 10
3 2
6 3
7 9 0 0
Sample Output
17
17
102
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的更多相关文章

  1. poj 1279 -- Art Gallery (半平面交)

    鏈接:http://poj.org/problem?id=1279 Art Gallery Time Limit: 1000MS   Memory Limit: 10000K Total Submis ...

  2. poj 1279 Art Gallery - 求多边形核的面积

    /* poj 1279 Art Gallery - 求多边形核的面积 */ #include<stdio.h> #include<math.h> #include <al ...

  3. 【POJ】【2068】Art Gallery

    计算几何/半平面交 裸的半平面交,关于半平面交的入门请看神犇博客:http://blog.csdn.net/accry/article/details/6070621 然而代码我是抄的proverbs ...

  4. 再来一道测半平面交模板题 Poj1279 Art Gallery

    地址:http://poj.org/problem?id=1279 题目: Art Gallery Time Limit: 1000MS   Memory Limit: 10000K Total Su ...

  5. poj 1279 Art Gallery (Half Plane Intersection)

    1279 -- Art Gallery 还是半平面交的问题,要求求出多边形中可以观察到多边形所有边的位置区域的面积.其实就是把每一条边看作有向直线然后套用半平面交.这题在输入的时候应该用多边形的有向面 ...

  6. UVA 10078 The Art Gallery

    Problem: Century Arts has hundreds of art galleries scattered all around the country and you are hir ...

  7. 【POJ 1279】Art Gallery

    http://poj.org/problem?id=1279 裸的半平面交的模板,按极角排序后维护一个双端队列,不要忘了最后要去除冗余,即最后一条边(或者更多的边)一定在双端队列里,但它不一定构成半平 ...

  8. POJ 1279 Art Gallery(半平面交)

    题目链接 回忆了一下,半平面交,整理了一下模版. #include <cstdio> #include <cstring> #include <string> #i ...

  9. 【POJ】1279 Art Gallery

    http://poj.org/problem?id=1279 题意:给一个n个点的多边形,n<=1500,求在多边形内能看到所有多边形上的点的面积. #include <cstdio> ...

随机推荐

  1. Python 36 死锁现象和递归锁、信号量、Event事件、线程queue

    一:死锁现象和递归锁 所谓死锁: 是指两个或两个以上的进程或线程在执行过程中,因争夺资源而造成的一种互相等待的现象,若无外力作用,它们都将无法推进下去.此时称系统处于死锁状态或系统产生了死锁,这些永远 ...

  2. UITextField 点击事件 --- 不会触发键盘弹出,触发其他事件的实现。

    今天在做项目的过程中,其中有三个控件: UITextField, UITextView , UILabel, 后来发现个问题:如果什么数据都不回填给textField.text 和 textView. ...

  3. myeclipse2014 破解步骤

    1.打开破解文件夹Myeclipse 2014 patch,运行run.bat文件 2.在破解界面中,usercode随便输入, systemid 在右边的SystemId按钮处,点击. 将自动生成一 ...

  4. Vue页面间传值,以及客户端数据存储

    初学Vue,遇到了页面传值的问题,大概网上学习了解了一下,在此跟大家分享一下学习心得,欢迎批评指正. 一.参数传值 如果是简单的页面传值,比如传一个id到详情页等等,推荐使用参数传值. 这里页面是通过 ...

  5. javascript 核心概念(1)-数据类型

    语法 (1)到现在为止,大多数浏览器也还是支持到ECMAScript 第三版的标准. 核心概念就是一个语言的基本工作原理,涉及语法,操作符,数据类型. (2)javascript的一切--变量,函数名 ...

  6. java Queue中 remove/poll, add/offer, element/peek区别

    offer,add区别: 一些队列有大小限制,因此如果想在一个满的队列中加入一个新项,多出的项就会被拒绝. 这时新的 offer 方法就可以起作用了.它不是对调用 add() 方法抛出一个 unche ...

  7. 用 Django2.0 做 简单的BBS(前端用 Bootstrap)

    实现目标: 开发首页显示BBS的标题和摘要,点击BBS的标题可跳转到BBS详细页面进行展示. 开发环境及开发工具: Python 3.6.3 Django 2.0 Pycharm 2017.3 实现过 ...

  8. LinkedList 源码

    1.类继承结构            结构: 2.成员及方法                 注意:其中      getFirst,getLast,removeFirst,removeLast,el ...

  9. CDC之Synchronizers

    1 Scenarios Two scenarios for passing signals across CDC boundaries: 1) sometimes it's not necessary ...

  10. js DOM 节点树 设置 style 样式属性

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...