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. angular分页指令

    目前的多个项目中都用到分页这个功能,为了提高可复用性,我特地分离出来写了个分页的指令.直接贴代码,详情如下: index.html <body id="sBill" ng-c ...

  2. 保存项目文件“XXX.csprj”时出错。类没有注册。

    [出错提示]保存项目文件“XXX”时出错.类没有注册.正在查找具有CLSID的对象:{D9B3211D-E57F-4426-AAEF-30A806ADD397}. [解决办法] 需要安装:MSXML_ ...

  3. Mozilla公布WebVR API标准草案

    随着信息技术的迅速发展,虚拟现实(Virtual Reality,VR)技术在近些年不断完善,其应用范围也变得十分广泛.为了搭建逼真的虚拟场景,VR技术一般都需要用到大量精美的图像和复杂的动作.因此, ...

  4. ArrayList与LinkedList实现比较

    1.ArrayList实现是基于数组来实现的,这可由ArrayList的源码看出: public class ArrayList<E> extends AbstractList<E& ...

  5. 一周一话题之三(Windows服务、批处理项目实战)

    -->目录导航 一. Windows服务 1. windows service介绍 2. 使用步骤 3. 项目实例--数据上传下载服务 二. 批处理运用 1. 批处理介绍 2. 基本语法 3. ...

  6. wpf 创建动画三种方式

    动画类型 : 故事版,CompositionTarget,DispachTime 那么到此,三种动态创建动画的方法都已经详细介绍过了,大家可能会有种感觉,比较钟情于第一种WPF/Silverlight ...

  7. Timer计时不准确的解决方案 每次都重新调整,修正误差

    http://stackoverflow.com/questions/29722838/system-timers-timer-steadily-increasing-the-interval 需要在 ...

  8. linux 复制文件时,报cp: omitting directory `XXX'

    今天在用linux命令进行文件复制时omitting cp -i BBS /opt/workspace/apache-tomcat-6,参数用的是 -i),所以也不太熟悉,原来,还有子目录文件,而是必 ...

  9. android学习——环境搭建之HelloWorld

    一.在开始Android开发之旅启动之前,首先要搭建环境,然后创建一个简单的HelloWorld.本文的主题如下: 1.1.JDK安装 1.2.Eclipse安装 1.3.Android SDK安装 ...

  10. EF框架搭建

    EF框架搭配lambda表达式使用起来非常高效便捷,有两种方法使用EF框架: 一是.添加“ADO.NET Entity Data Model”项,绑定配置数据库链接,勾选表和存储过程等,自动生成实体: ...