传送门:

https://zerojudge.tw/ShowProblem?problemid=a228

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

【题解】

插头dp第一题(难以置信我高中oi没有写过23333)

方程很简单,自己推一推插头的地方的连通性即可

放几张图跑了

# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm> using namespace std; typedef long long ll;
typedef unsigned long long ull;
typedef long double ld; const int M = + , MAX_STATUS = ( << ) + ;
const int mod = 1e9 + ; int n, m, a[M][M], tCase = ;
ll f[M][M][MAX_STATUS]; inline void sol() {
cin >> n >> m;
for (int i=; i<=n; ++i)
for (int j=; j<=m; ++j)
scanf("%d", &a[i][j]);
int STATUS_SIZE = ( << m+) - ;
int STATUS_SIZE_T = ( << m) - ;
f[][m][] = ;
for (int i=; i<=n; ++i) {
for (int sta=; sta<=STATUS_SIZE_T; ++sta) f[i][][sta << ] = f[i-][m][sta];
for (int j=; j<=m; ++j)
for (int sta=; sta<=STATUS_SIZE; ++sta) {
bool cur1 = (sta & ( << j-)), cur2 = (sta & ( << j));
if(a[i][j] == ) {
if(cur1 && cur2) f[i][j][sta] = f[i][j-][sta - ( << j-) - ( << j)];
else if(cur1 ^ cur2) {
int STA = (sta | ( << j-) | ( << j));
f[i][j][sta] = f[i][j-][STA - ( << j-)] + f[i][j-][STA - ( << j)];
} else f[i][j][sta] = f[i][j-][sta | ( << j-) | ( << j)];
} else {
if(!cur1 && !cur2) f[i][j][sta] = f[i][j-][sta];
else f[i][j][sta] = ;
}
}
}
cout << "Case " << ++tCase << ": There are " << f[n][m][] << " ways to eat the trees.\n";
} int main() {
int T;
cin >> T;
while(T--) sol();
return ;
}
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm> using namespace std; typedef long long ll;
typedef unsigned long long ull;
typedef long double ld; const int M = + , MAX_STATUS = ( << ) + ;
const int mod = 1e9 + ; int n, m, a[M][M], tCase = ;
int f[M][M][MAX_STATUS]; inline void sol() {
cin >> n >> m;
for (int i=; i<=n; ++i)
for (int j=; j<=m; ++j)
scanf("%d", &a[i][j]);
int STATUS_SIZE = ( << m+) - ;
int STATUS_SIZE_T = ( << m) - ;
f[][m][] = ;
for (int i=; i<=n; ++i) {
for (int sta=; sta<=STATUS_SIZE_T; ++sta) f[i][][sta << ] = f[i-][m][sta];
for (int j=; j<=m; ++j)
for (int sta=; sta<=STATUS_SIZE; ++sta) {
bool cur1 = (sta & ( << j-)), cur2 = (sta & ( << j));
if(a[i][j] == ) {
if(cur1 && cur2) f[i][j][sta] = f[i][j-][sta - ( << j-) - ( << j)];
else if(cur1 ^ cur2) {
int STA = (sta | ( << j-) | ( << j));
f[i][j][sta] = f[i][j-][STA - ( << j-)] + f[i][j-][STA - ( << j)];
if(f[i][j][sta] >= mod) f[i][j][sta] -= mod;
} else f[i][j][sta] = f[i][j-][sta | ( << j-) | ( << j)];
} else {
if(!cur1 && !cur2) f[i][j][sta] = f[i][j-][sta];
else f[i][j][sta] = ;
}
}
}
cout << "Case " << ++tCase << ": " << f[n][m][] << endl;
} int main() {
int T;
cin >> T;
while(T--) sol();
return ;
}

上面hdu,下面zerojudge

HDU1693 Eat the Trees(zerojudge a228)的更多相关文章

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

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

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

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

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

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

  4. Eat the Trees(hdu 1693)

    题意:在n*m的矩阵中,有些格子有树,没有树的格子不能到达,找一条或多条回路,吃完所有的树,求有多少中方法. 第一道真正意义上的插头DP,可参考陈丹琦的<基于连通性状态压缩的动态规划问题> ...

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

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

  6. HDU1693 Eat the Trees —— 插头DP

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

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

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

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

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

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

随机推荐

  1. Python入门:类与类的继承

    类,是一些有共同特征和行为事物的抽象概念的总和. 1. 定义一个类: 我们使用class来定义一个类,和之前说过的定义函数用def类似.在类里面给变量赋值时,专业术语称之为类的属性. 比如拿可口可乐来 ...

  2. HDU 2107 Founding of HDU

    http://acm.hdu.edu.cn/showproblem.php?pid=2107 Problem Description 经过慎重的考虑,XHD,8600, LL,Linle以及RPG等A ...

  3. win32.gui.api.con(前置,鼠标点击,发送数据的Dome)

    # -*- coding: UTF-8 -*- import win32gui, win32con import os import time import win32gui import win32 ...

  4. Json的JsonValueProcessor方法

    将对象转换成字符串,是非常常用的功能,尤其在WEB应用中,使用 JSON lib 能够便捷地完成这项工作. JSON lib能够将Java对象转成json格式的字符串,也可以将Java对象转换成xml ...

  5. Oracle 11G RAC For Windows 2008 R2部署手册(亲测,成功实施多次)

    总体规划 服务器规划 1.建议使用两台硬件配置一模一样的服务器来作为 RAC 环境的两个物理节点 2.服务器至少需要配置两块物理网卡 3.服务器规划表: 节点 主机名 本地磁盘大小 操作系统 内存大小 ...

  6. laravel报404错误与NGINX报404错误区别

      nginx自己配置的404页面 和laravel配置的404页面:如果报了404 :执行laravel的404页面: 那这个404页面对nginx来说意味着什么    laravel 路由和页面找 ...

  7. iframe & cors

    iframe & cors <!DOCTYPE html> <html lang="zh-Hans"> <head> <meta ...

  8. YARN结构分析与工作流程

    YARN Architecture Link: http://hadoop.apache.org/docs/r2.7.2/hadoop-yarn/hadoop-yarn-site/YARN.html ...

  9. 【bzoj3527】 Zjoi2014—力

    http://www.lydsy.com/JudgeOnline/problem.php?id=3527 (题目链接) 题意 $${F_i=\sum_{j<i} {\frac{q_iq_j}{( ...

  10. nth-of-type和nth-child

    一.nth-of-type.nth-child :nth-of-type(n) 选择器匹配属于父元素的特定类型的第 N 个子元素的每个元素. :nth-child(n) 选择器匹配属于其父元素的第 N ...