题目:http://acm.hdu.edu.cn/showproblem.php?pid=1693

第一道插头 DP !

直接用二进制数表示状态即可。

#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=,M=(<<)+;
int n,m,bin[N];ll dp[N][N][M];
int b[N][N];
void solve()
{
int lm=m+;
bin[]=;for(int i=;i<=lm;i++)bin[i]=bin[i-]<<;
memset(dp,,sizeof dp); dp[][][]=;
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
for(int s=;s<bin[lm];s++)
{
if(!dp[i][j][s])continue;
ll tp=dp[i][j][s];bool d0=s&bin[j-],d1=s&bin[j];
// ll tp not int tp!!!!!
if(!b[i][j])
{
if(!d0&&!d1)dp[i][j+][s]+=tp;
continue;
}
int t=s^bin[j-]^bin[j];
if((d0&&d1)||(!d0&&!d1))
dp[i][j+][t]+=tp;
if((d0&&!d1)||(!d0&&d1))
dp[i][j+][s]+=tp, dp[i][j+][t]+=tp;
}
for(int s=;s<bin[lm];s++)
{
if(!dp[i][lm][s]||s&bin[m])continue;
dp[i+][][s<<]+=dp[i][lm][s];
}
}
}
int main()
{
int T; scanf("%d",&T);
for(int t=;t<=T;t++)
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
scanf("%d",&b[i][j]);
solve();
printf("Case %d: There are %lld ways to eat the trees.\n",
t,dp[n][m+][]);
}
return ;
}

hdu 1693 Eat the Trees——插头DP的更多相关文章

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

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

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

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

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

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

  4. HDU 1693 Eat the Trees(插头DP、棋盘哈密顿回路数)+ URAL 1519 Formula 1(插头DP、棋盘哈密顿单回路数)

    插头DP基础题的样子...输入N,M<=11,以及N*M的01矩阵,0(1)表示有(无)障碍物.输出哈密顿回路(可以多回路)方案数... 看了个ppt,画了下图...感觉还是挺有效的... 参考 ...

  5. HDU - 1693 Eat the Trees(多回路插头DP)

    题目大意:要求你将全部非障碍格子都走一遍,形成回路(能够多回路),问有多少种方法 解题思路: 參考基于连通性状态压缩的动态规划问题 - 陈丹琦 下面为代码 #include<cstdio> ...

  6. HDU 1693 Eat the Trees(插头DP,入门题)

    Problem Description Most of us know that in the game called DotA(Defense of the Ancient), Pudge is a ...

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

    题意:给一个n*m的矩阵,为1时代表空格子,为0时代表障碍格子,问如果不经过障碍格子,可以画一至多个圆的话,有多少种方案?(n<12,m<12) 思路: 这题不需要用到最小表示法以及括号表 ...

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

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

  9. HDU 1693 Eat the Trees

    第一道(可能也是最后一道)插头dp.... 总算是领略了它的魅力... #include<iostream> #include<cstdio> #include<cstr ...

随机推荐

  1. 关于时间戳截取的隐藏bug

    之前写时间戳,要截取后六位 原写法: function timeStamp() { const date = new Date() const month = date.getMonth() + 1 ...

  2. mysql cast

    之前讲到了orcale的字符串与日期等类型的转换,现在我们来看看Mysql是怎么转换的.比起orcale,MySQL相比之下就简单得多了,只需要一个Cast()函数就能搞定.其语法为:Cast(字段名 ...

  3. outlook2016中如何设置两个账户都自动有各自默认签名

    安装了Outlook2016以后,有些朋友不清楚,我们在发送邮件的时候,怎么添加邮件签名,其实在Outlook2016中添加邮件签名的方法也是比较简单的,这里小编介绍下在Outlook2016中设置添 ...

  4. Python 关联关系

    class Boy: def __init__(self, name, girlFriend=None): # 在初始化的时候可以给一个对象的属性设置成另一个类的对象 self.girlFriend ...

  5. angular 学习日志

    1.创建项目 npm install -g @angular/cli ng new my-app cd my-app ng serve --open // 或者 npm start 2.生成新模块 n ...

  6. nexus和maven的安装与配置

    如果用普通用户安装就需要创建用户 属组例 groupadd configer  //创建用户组 useradd -g configer configer  //创建用户并指定用户组 passwd co ...

  7. Kaggle:Home Credit Default Risk 数据探索及可视化(1)

    最近博主在做个 kaggle 竞赛,有个 Kernel 的数据探索分析非常值得借鉴,博主也学习了一波操作,搬运过来借鉴,原链接如下: https://www.kaggle.com/willkoehrs ...

  8. MongDB篇,第四章:数据库知识4

    MongDB 数据库知识4 GridFS 大文件存储 文件的数据库存储 1,在数据库中以   字符串的方式  存储文件在本地的路径: 优点: 节省数据库空间 缺点: 当数据库或者文件位置发生变化时则无 ...

  9. django安装命令

    通过pip安装Django   ==指定版本号 pip install Django==2.0.2 查看djangoshifou安装成功:1.进入python ,2.import   django 查 ...

  10. Arcgis发布服务

    1.文件<<共享为<<服务. 2.发布服务<<在下拉菜单选择已经创建的server连接,输入服务名称<<选择服务发布的位置(默认在根目录下,也可以在子文 ...