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的更多相关文章

  1. codeforces 111C/112E Petya and Spiders

    题目: Petya and Spiders传送门: http://codeforces.com/problemset/problem/111/C http://codeforces.com/probl ...

  2. Petya and Spiders【二进制状压】

    题目链接[http://codeforces.com/problemset/problem/111/C] 题意:给出大小为N*M的图(1 ≤ n, m ≤ 40, n·m ≤ 40),每个图中有一个蜘 ...

  3. 【Codeforces 111C】Petya and Spiders

    Codeforces 111 C 题意:给\(n\times m\)的网格,每个点上有一个蜘蛛,每个蜘蛛可以向上.下.左.右走一步或者不动,问最多能存在多少没有蜘蛛的点. 思路1: 首先因为\(n\) ...

  4. 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 ...

  5. aes加密C语言

    /** * \file aes.h * * \brief AES block cipher * * Copyright (C) 2006-2010, Brainspark B.V. * * This ...

  6. 自己动手写RTP服务器——关于RTP协议

    转自:http://blog.csdn.net/baby313/article/details/7353605 本文会带领着你一步步动手实现一个简单的RTP传输服务器,旨在了解RTP流媒体传输协议以及 ...

  7. 自己写RTPserver——大约RTP协议

    自己写RTPserver--大约RTP协议 本文将带领你一步一步地实现一个简单的手RTP变速器server,旨在了解RTP流媒体传输协议以及有关多媒体编解码器的一些知识. RTP协议的必备知识 要动手 ...

  8. [原]CentOS7安装Rancher2.1并部署kubernetes (二)---部署kubernetes

    ##################    Rancher v2.1.7  +    Kubernetes 1.13.4  ################ ##################### ...

  9. 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 ...

随机推荐

  1. MyEclipse过期激活方法

    如果已经过期会提示,进行购买.重新激活和退出,我们选择重新激活. 打开浏览器,地址栏输入key.858game.com,然后输入名称,在线获得MyEclipse的激活码. 输入Sumscripter: ...

  2. C#之装箱与拆箱

    C#中值类型和和引用类型实质上是同源的,所以不但可以从值类型和引用类型之间进行转换,也可以在值类型和引用类型之间进行转换.,但是两者使用的内存类型不同,使他们的转换变得复杂. 1.装箱: 在C#中通常 ...

  3. [Leetcode] Validate BST

    给一个Binary Tree,检查是不是Binary Search Tree. 即是否满足对每个节点,左子树的中的所有节点的值 < 当前节点的值 < 右子树所有节点的值. Solution ...

  4. how to develop mobile web

    http://blog.templatemonster.com/2010/05/11/how-make-mobile-website-6-easy-tips/ http://mobile.smashi ...

  5. tornado异步请求的理解(转)

    tornado异步请求的理解 http://www.kankanews.com/ICkengine/archives/88953.shtml 官网第一段话: Tornado is a Python w ...

  6. IIS tomcat共用80端口解决一个IP多个域名:使用Nginx反向代理方式使两者兼容

    环境: windows server 2003,IIS6服务器,Tomcat7服务器 域名有几个: 以下是使用IIS的域名: http://www.formuch.com/ http://www.fo ...

  7. ANDROID_MARS学习笔记_S05_004_过滤杂质,得到真正的加速度

    一.简介 二.代码1.java (1)MainActivity.java import android.app.Activity; import android.content.Context; im ...

  8. redis pub/sub 发布订阅

    Redis的列表数据结构有blpop和brpop命令,能从列表里返回且删除第一个(或最后一个)元素,或者被堵塞,直到有一个元素可供操作.这可以用来实现一个简单的队列.(参考:http://www.cn ...

  9. PHP curl传输文件的版本兼容性

    /** * 存储文件到远程服务器 * * @param string $filePath * 文件绝对路径 * @param string $fileSaveUrl * 存储的远程目标地址 * @pa ...

  10. SQL中Case When的使用方法

    Case具有两种格式.简单Case函数和Case搜索函数. --简单Case函数 CASE sex ' THEN '男' ' THEN '女' ELSE '其他' END       --Case搜索 ...