原文链接http://www.cnblogs.com/zhouzhendong/p/8433484.html

题目传送门 - HDU1693

题意概括

  多回路经过所有格子的方案数。

做法

  最基础的插头dp裸题。

  只要一个横向插头和一排纵向插头就可以了。

  分类也很少。

  插头dp -> http://www.cnblogs.com/zinthos/p/3897854.html

代码

#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef unsigned long long ULL;
const int N=15,S=1<<12;
int T,n,m,f[N][N];
ULL dp[2][S];
int main(){
scanf("%d",&T);
int Case=0;
while (T--){
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
scanf("%d",&f[i][j]);
memset(dp,0,sizeof dp);
int T0=1,T1=0,s=1<<(m+1);
dp[0][0]=1;
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++){
T0^=1,T1^=1;
memset(dp[T1],0,sizeof dp[T1]);
for (int x=0;x<s;x++){
if (!dp[T0][x])
continue;
if (!f[i][j]){
if (!(x&1)&&!((x>>j)&1))
dp[T1][x]+=dp[T0][x];
continue;
}
int L=x&1,U=(x>>j)&1;
if (L&&U)
dp[T1][x^1^(1<<j)]+=dp[T0][x];
if (L&&!U)
dp[T1][x]+=dp[T0][x],dp[T1][x^1^(1<<j)]+=dp[T0][x];
if (!L&&U)
dp[T1][x]+=dp[T0][x],dp[T1][x^1^(1<<j)]+=dp[T0][x];
if (!L&&!U)
dp[T1][x^1^(1<<j)]+=dp[T0][x];
}
}
for (int x=0;x<s;x++)
if (x&1)
dp[T1][x]=0;
}
printf("Case %d: There are %llu ways to eat the trees.\n",++Case,dp[T1][0]);
}
return 0;
}

  

HDU1693 Eat the Trees 插头dp的更多相关文章

  1. HDU1693 Eat the Trees —— 插头DP

    题目链接:https://vjudge.net/problem/HDU-1693 Eat the Trees Time Limit: 4000/2000 MS (Java/Others)    Mem ...

  2. hdu1693 Eat the Trees [插头DP经典例题]

    想当初,我听见大佬们谈起插头DP时,觉得插头DP是个神仙的东西. 某大佬:"考场见到插头DP,直接弃疗." 现在,我终于懂了他们为什么这么说了. 因为-- 插头DP很毒瘤! 为什么 ...

  3. HDU 1693 Eat the Trees(插头DP)

    题目链接 USACO 第6章,第一题是一个插头DP,无奈啊.从头看起,看了好久的陈丹琦的论文,表示木看懂... 大体知道思路之后,还是无法实现代码.. 此题是插头DP最最简单的一个,在一个n*m的棋盘 ...

  4. hdu 1693 Eat the Trees——插头DP

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1693 第一道插头 DP ! 直接用二进制数表示状态即可. #include<cstdio> # ...

  5. HDU 1693 Eat the Trees ——插头DP

    [题目分析] 吃树. 直接插头DP,算是一道真正的入门题目. 0/1表示有没有插头 [代码] #include <cstdio> #include <cstring> #inc ...

  6. hdu1693 Eat the Trees 【插头dp】

    题目链接 hdu1693 题解 插头\(dp\) 特点:范围小,网格图,连通性 轮廓线:已决策点和未决策点的分界线 插头:存在于网格之间,表示着网格建的信息,此题中表示两个网格间是否连边 状态表示:当 ...

  7. hdu1693:eat trees(插头dp)

    题目大意: 题目背景竟然是dota!屠夫打到大后期就没用了,,只能去吃树! 给一个n*m的地图,有些格子是不可到达的,要把所有可到达的格子的树都吃完,并且要走回路,求方案数 题解: 这题大概是最简单的 ...

  8. [Hdu1693]Eat the Trees(插头DP)

    Description 题意:在n*m(1<=N, M<=11 )的矩阵中,有些格子有树,没有树的格子不能到达,找一条或多条回路,吃完所有的树,求有多少种方法. Solution 插头DP ...

  9. 2019.01.23 hdu1693 Eat the Trees(轮廓线dp)

    传送门 题意简述:给一个有障碍的网格图,问用若干个不相交的回路覆盖所有非障碍格子的方案数. 思路:轮廓线dpdpdp的模板题. 同样是讨论插头的情况,只不过没有前一道题复杂,不懂的看代码吧. 代码: ...

随机推荐

  1. Sq lServer触发器的使用

    创建表: CREATE TABLE [dbo].[GeneralRule]( [ID] [int] NOT NULL, ) NULL, [DeleteFlag] [int] NOT NULL ) CR ...

  2. word在线预览编辑器

    https://blog.csdn.net/liuli283/article/details/73776685 https://blog.csdn.net/mxljiayou/article/deta ...

  3. C# 使用EPPlus 秒导出10万条数据

    1.先要引用dll文件,可以直接使用vs自带的包管理,如下图: 输入 EPPlus 我这里是安装过了的所以这里显示的是卸载而不是安装. 安装成功了之后会看到这个dll文件 代码如下: //导出Exce ...

  4. Go语言从入门到放弃(一) 变量/常量/函数

    HelloWorld 我们先看看一个最简单的HelloWorld代码 package main import "fmt" func main() { fmt.Println(&qu ...

  5. Vue中的render函数随笔

    使用vue-cli创建项目后,再main.js里面有这样一段代码: new Vue({ render:h => h(App) }).$mount('#app') render函数是渲染一个视图, ...

  6. android招聘啦,美图秀秀欢迎你加入!

    前言 最近朋友公司招聘,美图秀秀大家一定很熟悉吧,欢迎你的加入. 了解相关更多技术以外的,可参考<除了敲代码,你还有什么副业吗?>,再往下看,今天给需要换工作或者还未找到工作的童鞋们谋一个 ...

  7. url加密和解密

    .NET中加密和解密有两种方式 string file="文件上(传)篇.doc";string Server_UrlEncode=Server.UrlEncode(file);s ...

  8. Node.js 调存储过程

    var spring = require("spring"); //当前登录人ID var account_id = require('nodejava').toJs.parse( ...

  9. java报错:The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files

    看包的路径是否对对:比如这样不对(...src/object/obietc) 其它解决方法转载: https://www.cnblogs.com/yadongliang/p/5918228.html ...

  10. 批量杀掉多个pid文件中记录的pid进程, 并集成到shell脚本中

    head_files=`find ./fmsConf/ -name "*.pid"` for file in $head_files do cat $file | awk rm - ...