插头DP

  插头dp模板题……

  这题比CDQ论文上的例题还要简单……因为不用区分左右插头(这题可以多回路,并不是一条哈密尔顿路)

  硬枚举当前位置的状态就好了>_<

  题解:http://blog.csdn.net/xymscau/article/details/6756351

 //HDU 1693
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
using namespace std;
int getint(){
int v=,sign=; char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') sign=-; ch=getchar();}
while(isdigit(ch)) {v=v*+ch-''; ch=getchar();}
return v*sign;
}
/*******************template********************/
const int N=;
typedef long long LL;
int mp[N][N];
LL dp[N][N][<<N];
int n,m; void DP(){
memset(dp,,sizeof (dp));
dp[][m][]=;
F(i,,n){//第i行
// for(int j=0;j<(1<<m);j++)
rep(j,(<<m))
dp[i][][(j<<)]=dp[i-][m][j];
//换行(将上一行最后一格状态放到这一行第一格,方便转移……) F(k,,m)//第k个格子
rep(sta,<<(m+)){//枚举当前状态sta
int y=<<k,x=<<(k-);
if(mp[i][k]){//如果当前格子无障碍
if( (sta&x)!= && (sta&y)!= )//如果状态为(1,1)
dp[i][k][sta]=dp[i][k-][sta-x-y];//从(0,0)转移过来
else if( (sta&x)== && (sta&y)== )//如果状态为(0,0)
dp[i][k][sta]=dp[i][k-][sta+x+y];//从(1,1)转移过来
else //状态为(0,1)或(1,0)则从(1,0)&&(0,1)转过来
dp[i][k][sta]=dp[i][k-][sta^x^y]+dp[i][k-][sta];
}//如果当前格子有障碍
else
if( (sta&x)== && (sta&y)==)//若当前状态为(0,0)
dp[i][k][sta]=dp[i][k-][sta];//则ans从前一格
else
dp[i][k][sta]=;
}
}
printf("There are %lld ways to eat the trees.\n",dp[n][m][]);
}
int main(){
int T=getint(),num=;
while(T--){
num++;
n=getint();m=getint();
F(i,,n)
F(j,,m) mp[i][j]=getint();
printf("Case %d: ",num);
DP();
}
return ;
}

(带注释)

【HDOJ】【1693】Eat The Trees的更多相关文章

  1. 【HDU】1693:Eat the Trees【插头DP】

    Eat the Trees Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  2. 【HDOJ图论题集】【转】

    =============================以下是最小生成树+并查集====================================== [HDU] How Many Table ...

  3. 【集训笔记】博弈论相关知识【HDOJ 1850【HDOJ2147

    以下资料来自:http://blog.csdn.net/Dinosoft/article/details/6795700 http://qianmacao.blog.163.com/blog/stat ...

  4. 【HDU】1693 Eat the Trees

    http://acm.hdu.edu.cn/showproblem.php?pid=1693 题意:n×m的棋盘求简单回路(可以多条)覆盖整个棋盘的方案,障碍格不许摆放.(n,m<=11) #i ...

  5. hdu 1693 : Eat the Trees 【插头dp 入门】

    题目链接 题意: 给出一个n*m大小的01矩阵,在其中画线连成封闭图形,其中对每一个值为1的方格,线要恰好穿入穿出共两次,对每一个值为0的方格,所画线不能经过. 参考资料: <基于连通性状态压缩 ...

  6. 【HDOJ 5654】 xiaoxin and his watermelon candy(离线+树状数组)

    pid=5654">[HDOJ 5654] xiaoxin and his watermelon candy(离线+树状数组) xiaoxin and his watermelon c ...

  7. 【HDU1693】Eat the Trees(插头dp)

    [HDU1693]Eat the Trees(插头dp) 题面 HDU Vjudge 大概就是网格图上有些点不能走,现在要找到若干条不相交的哈密顿回路使得所有格子都恰好被走过一遍. 题解 这题的弱化版 ...

  8. 【HDOJ 5379】 Mahjong tree

    [HDOJ 5379] Mahjong tree 往一颗树上标号 要求同一父亲节点的节点们标号连续 同一子树的节点们标号连续 问一共同拥有几种标法 画了一画 发现标号有二叉树的感觉 初始标号1~n 根 ...

  9. HDOJ 1238 Substrings 【最长公共子串】

    HDOJ 1238 Substrings [最长公共子串] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...

随机推荐

  1. Swift学习链接

    http://wiki.jikexueyuan.com/project/swift/chapter1/02_a_swift_tour.html

  2. Cocos2d-x场景切换相关函数介绍

    场景切换是通过导演类Director实现的,其中的相关函数如下: runWithScene(Scene* scene).该函数可以运行场景.只能在启动第一个场景时候调用该函数.如果已经有一个场景运行情 ...

  3. iOS定位 - 普通定位(没有地图) - 反地理编码(得到具体位置)

    #import <CoreLocation/CoreLocation.h> 使用到的头文件 要引入CoreLocation这个包 <CLLocationManagerDelegate ...

  4. C# 数据操作工具类

    CREATE PROCEDURE [dbo].[RecordFromPage] @SelectList VARCHAR(max), @TableSource VARCHAR(100), @Search ...

  5. 20150301—ASP.NET的Repeater

    Repeater与GridView等数据列表一样,都是用来显示数据库的信息的,其中Repeater是最基本的列表形式,其用法也比较灵活. 一.Repeater的位置: 工具箱-数据-Repeater ...

  6. php折线图 布局图

    例子1: 1 <?php require_once("../conf.php"); ?> <!DOCTYPE HTML> <html> < ...

  7. 【风马一族_git_github】git与github的英文记录

    Pull requests  Issues Gist 请求 问题 要点 ---------------------------------------------------------------- ...

  8. cadence16.3破解方法

    今天安装cadence16.3,安装了两遍都失败了,百思不得其解,结果总是出现在license上,如下图所示: 后面当然就只能启动demo版了,于是网上找,参照以前古老的法子,终于解决问题! 首先,开 ...

  9. Ubuntu 14.04下java开发环境的搭建--3--Tomcat及MySQL的安装

    前面两篇文章,已经说明了JDK和Eclipse 的安装方法,下面简单说一下,Tomcat及MySQL的安装方法. Tomcat的安装. 在合适的地方解压apache-tomcat-6.0.39.tar ...

  10. linq 日常关键字使用

    1.from var scoreQuery = from student in students from score in student.Scores where score > 90 se ...