hdu 1693 Eat the Trees——插头DP
题目: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的更多相关文章
- HDU 1693 Eat the Trees(插头DP)
题目链接 USACO 第6章,第一题是一个插头DP,无奈啊.从头看起,看了好久的陈丹琦的论文,表示木看懂... 大体知道思路之后,还是无法实现代码.. 此题是插头DP最最简单的一个,在一个n*m的棋盘 ...
- HDU 1693 Eat the Trees ——插头DP
[题目分析] 吃树. 直接插头DP,算是一道真正的入门题目. 0/1表示有没有插头 [代码] #include <cstdio> #include <cstring> #inc ...
- hdu1693 Eat the Trees [插头DP经典例题]
想当初,我听见大佬们谈起插头DP时,觉得插头DP是个神仙的东西. 某大佬:"考场见到插头DP,直接弃疗." 现在,我终于懂了他们为什么这么说了. 因为-- 插头DP很毒瘤! 为什么 ...
- HDU 1693 Eat the Trees(插头DP、棋盘哈密顿回路数)+ URAL 1519 Formula 1(插头DP、棋盘哈密顿单回路数)
插头DP基础题的样子...输入N,M<=11,以及N*M的01矩阵,0(1)表示有(无)障碍物.输出哈密顿回路(可以多回路)方案数... 看了个ppt,画了下图...感觉还是挺有效的... 参考 ...
- HDU - 1693 Eat the Trees(多回路插头DP)
题目大意:要求你将全部非障碍格子都走一遍,形成回路(能够多回路),问有多少种方法 解题思路: 參考基于连通性状态压缩的动态规划问题 - 陈丹琦 下面为代码 #include<cstdio> ...
- 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 ...
- HDU 1693 Eat the Trees (插头DP)
题意:给一个n*m的矩阵,为1时代表空格子,为0时代表障碍格子,问如果不经过障碍格子,可以画一至多个圆的话,有多少种方案?(n<12,m<12) 思路: 这题不需要用到最小表示法以及括号表 ...
- hdu 1693 : Eat the Trees 【插头dp 入门】
题目链接 题意: 给出一个n*m大小的01矩阵,在其中画线连成封闭图形,其中对每一个值为1的方格,线要恰好穿入穿出共两次,对每一个值为0的方格,所画线不能经过. 参考资料: <基于连通性状态压缩 ...
- HDU 1693 Eat the Trees
第一道(可能也是最后一道)插头dp.... 总算是领略了它的魅力... #include<iostream> #include<cstdio> #include<cstr ...
随机推荐
- LeetCode子集问题
给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(子集当中不包括重复的元素) 代码如下: def subsets(nums): target=[[]] for num in nums ...
- Python中替换敏感字
敏感词在文本文件document.txt中,当用户输入敏感词语时,用*号代替并打印出来 document.txt中的文件内容如下: 北京 上海 广州 深圳 领导 test.py content=inp ...
- 莫烦tensorflow(3)-Variable
import tensorflow as tf state = tf.Variable(0,name='counter') one = tf.constant(1) new_value = tf.ad ...
- Bug01_MyBatis_不允许有匹配 "[xX][mM][lL]" 的处理指令目标。
xml 文件格式不正确.一般是开头约束不对. 我出现的问题是:<?xml version="1.0" encoding="UTF-8"?>写了两遍, ...
- getAttribLocation的返回值
var coord = gl.getAttribLocation(shaderProgram, "coordinates"); // 0 var coord2 = gl.ge ...
- 动态规划-----hdu 1024 (区间连续和)
给定一个长度为n的区间:求m段连续子区间的和 最大值(其中m段子区间互不相交) 思路: dp[i][j]: 前j个元素i个连续区间最大值 (重要 a[j]必须在最后一个区间内) 转移方程:dp[i][ ...
- MyBatis like函数使用注意事项
百分号后面必须要加上空格,不然会将后面的字符串全部都黏在一起,导致sql语句运行报错
- 字符串转json格式
方法一:var json = JSON.parse(str)方法二:eval
- HDU 2561
F - 第二第二 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Prac ...
- java-BigInteger类
1.BigInteger类的概述和方法使用 * A:BigInteger的概述 * 可以让超过Integer范围内的数据进行运算 * B:构造方法 * public BigInteger(String ...