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 ...
随机推荐
- crontab的定时任务实例
实例1:每1分钟执行一次myCommand * * * * * myCommand 实例2:每小时的第3和第15分钟执行 3,15 * * * * myCommand 实例3:在上午8点到11点的第3 ...
- python-django的生命周期
wsgi,请求封装后交给web框架(flask,django) 中间件,对请求进行校验或在请求对象中添加其他相关数据,列如(scrf[跨域],request,session) 路由匹配,根据浏览器发送 ...
- JAVA按顺序播放多个wav音频
用Java按顺序播放多个音频部件,不是同时播放.代码如下: List<String> files = new ArrayList<String>(); files.add(&q ...
- linux 如何使用密钥登录 (CentOs)
说明:一般的密码方式登录容易被密码暴力破解.所以一般我们会将 SSH 的端口设置为默认22以外的端口,或者禁用root账户登录.其实可以通过密钥登录这种方式来更好地保证安全. 密钥形式登录的原理是:利 ...
- Mariadb-10.1.22配置项
## These groups are read by MariaDB server.# Use it for options that only the server (but not client ...
- thrift使用案例
参考资料:http://www.ibm.com/developerworks/cn/java/j-lo-apachethrift/ 首先是定义thrift IDL接口,如下(SunTelTc.thri ...
- 基于hiredis,redis C客户端封装
项目中需要用到redis就封装了一下,基于hiredis,只封装了string和哈希的部分方法.编译时加入-D__USER_LOCK__添加线程安全. suntelRedisCli.h #ifndef ...
- Vue.js学习使用心得(一)
一.初步了解 Vue.js是一套构建用户界面的渐进式框架,它只关注视图层, 采用自底向上增量开发的设计. Vue 的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件,相当于JavaS ...
- 陕西师范第七届K题----动态规划
ps: 自己的方法绝对是弱爆了 肯定存在更优的方法 O(n^3)复杂度 暴力求解的.. 链接:https://www.nowcoder.com/acm/contest/121/K来源:牛客网 柯怡最近 ...
- (15)模型层-什么是ORM
ORM是什么 1.MVC或者MTV框架中包括一个重要的部分,就是ORM,它实现了数据模型与数据库的解耦,即数据模型的设计不需要依赖于特定的数据库,通过简单的配置就可以轻松更换数据库,这极大的减轻了开发 ...