cf 85 E. Petya and Spiders
http://codeforces.com/contest/112/problem/E
轮廓线dp。每一个格子中的蜘蛛选一个去向。终于,使每一个蜘蛛都有一个去向,同一时候保证有蜘蛛的格子最少。须要用4进制模拟
此题还能够用DLX+二分来解,这个解法相对于轮廓线dp就非常无脑了,不用考虑细节。以后再补上
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <vector>
#include <set>
using namespace std; typedef long long LL;
const int INF = 0x3f3f3f3f;
const int maxn = 100010;
int n, m;
const int MALL = 1 << 14; int dp[2][MALL];
///00 up, left; 01 stall; 10 right; 11 down;
int now, next;
int ALL;
int ans;
void update(int r, int nextr, int val)
{
nextr &= ALL;
dp[next][nextr] = max(dp[next][nextr], dp[now][r] + val);
}
int getI(int x, int i)
{
return (x >> (2 * i))&3;
}
int main()
{
while (cin >> n >> m)
{
if (n < m) swap(n, m);
ALL = (1 << (m * 2)) - 1; memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
now = 0; next = 1; for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
for (int r = 0; r <= ALL; r++)
{
if (dp[now][r] != -1)
if ((j && getI(r, 0) == 2) || (i && getI(r, m - 1) == 3))
{
update(r, (r << 2) + 1, 0);
continue;
}
update(r, (r << 2) + 1, 0);
if (j && getI(r, 0) == 1 ) update(r, r << 2, 1);///left 00 if (i && getI(r, m - 1) == 1 ) update(r, r << 2, 1);///up 00 if (j < m - 1) update(r, (r << 2) + 2, 1);///right 10 if (i < n - 1) update(r, (r << 2) + 3, 1);///down 11
}
memset(dp[now], -1, sizeof(dp[now]));
next = now; now ^= 1;
}
}
ans = 0;
for (int i = 0; i <= ALL; i++)
ans = max(ans, dp[now][i]);
cout << ans << endl;
}
}
版权声明:本文博主原创文章。博客,未经同意不得转载。
cf 85 E. Petya and Spiders的更多相关文章
- codeforces 111C/112E Petya and Spiders
题目: Petya and Spiders传送门: http://codeforces.com/problemset/problem/111/C http://codeforces.com/probl ...
- Petya and Spiders【二进制状压】
题目链接[http://codeforces.com/problemset/problem/111/C] 题意:给出大小为N*M的图(1 ≤ n, m ≤ 40, n·m ≤ 40),每个图中有一个蜘 ...
- 【Codeforces 111C】Petya and Spiders
Codeforces 111 C 题意:给\(n\times m\)的网格,每个点上有一个蜘蛛,每个蜘蛛可以向上.下.左.右走一步或者不动,问最多能存在多少没有蜘蛛的点. 思路1: 首先因为\(n\) ...
- Codeforces Beta Round #85 (Div. 1 Only) C (状态压缩或是数学?)
C. Petya and Spiders Little Petya loves training spiders. Petya has a board n × m in size. Each cell ...
- aes加密C语言
/** * \file aes.h * * \brief AES block cipher * * Copyright (C) 2006-2010, Brainspark B.V. * * This ...
- 自己动手写RTP服务器——关于RTP协议
转自:http://blog.csdn.net/baby313/article/details/7353605 本文会带领着你一步步动手实现一个简单的RTP传输服务器,旨在了解RTP流媒体传输协议以及 ...
- 自己写RTPserver——大约RTP协议
自己写RTPserver--大约RTP协议 本文将带领你一步一步地实现一个简单的手RTP变速器server,旨在了解RTP流媒体传输协议以及有关多媒体编解码器的一些知识. RTP协议的必备知识 要动手 ...
- [原]CentOS7安装Rancher2.1并部署kubernetes (二)---部署kubernetes
################## Rancher v2.1.7 + Kubernetes 1.13.4 ################ ##################### ...
- Codeforces Beta Round #85 (Div. 1 Only) B. Petya and Divisors 暴力
B. Petya and Divisors Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/111 ...
随机推荐
- 移动App双周版本迭代实战--转载备用
对于移动互联网产品来说,迭代的速度就是生命.我创业时做移动App时是一周一版,而现在是2周1版.相比起小公司,大公司迭代时间虽长,却更为不易,因为大公司流程更多,参与人数更多,需求更多,实现这样的快速 ...
- java WebService简单使用案例
首先,建立一个WebService: package garfield; import javax.jws.WebService; import javax.xml.ws.Endpoint; @Web ...
- VS2008编译器编译出来的文件比mingw编译的要几乎小一半
为什么要在VS2008中使用QT静态编译呢?很简单,因为VS2008编译器编译出来的文件比mingw编译的要几乎小一半. 好了现在我们来做些准备工作,VS2008自然要安装的,然后打上SP1的补丁.然 ...
- ruby Methods, Procs, Lambdas, and Closures
define simple method定义简单方法 关键字def用于方法定义,在其后是方法名和可选的参数名列表,参数名列表会用一对圆括号括住.构成方法主体的代码放在参数列表之后,end用于结束方法定 ...
- statspack系列6
原文:http://jonathanlewis.wordpress.com/2006/12/27/analysing-statspack-6/ 作者:Jonathan Lewis 下面是一段时间以前网 ...
- bzoj1570
购买的机票限制和数据范围很容易想到是网络流不难想到每个城市按时刻拆点,这也是一个经典模型由于时间不会太大,我们穷举时间,不断在残留网络上建图,跑最大流直至总流量为k即可 ; type node=rec ...
- IIS7部署ASP.NET MVC4程序报错解决
今天安装了windows7 开发web项目需要安装IIS,当安装完以后,web程序已经映射到了本地IIS上,运行出现如下错误提示 处理程序“PageHandlerFactory-Integrated” ...
- (转载)AS3中的mouseEnabled与mouseChildren
(转载)http://www.cnblogs.com/gongchen/archive/2013/05/09/3069055.html mouseEnabled与mouseChildren都是用来确定 ...
- Devexpress 之gridControl
1.gridControl如何去掉主面板? 鼠标右键Run Designer=>OptionsView => ShowGroupPanel=False: 2.gridControl如何设置 ...
- Rank of Tetris HDU--1881
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...