hdu1693Eat the Trees(插头dp)
先坑着,等啥时候会了再来填坑
不得不说思路真的是很妙啊
//minamoto
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[<<],*p1=buf,*p2=buf;
inline int read(){
#define num ch-'0'
char ch;bool flag=;int res;
while(!isdigit(ch=getc()))
(ch=='-')&&(flag=true);
for(res=num;isdigit(ch=getc());res=res*+num);
(flag)&&(res=-res);
#undef num
return res;
}
const int N=;
int n,m,bin[N],mp[N][N];
ll f[N][N][(<<)+];
void solve(int x,int y){
int plug1=bin[y-],plug2=bin[y];
if(mp[x][y]){
for(int j=;j<bin[m+];++j){
f[x][y][j]+=f[x][y-][j^plug1^plug2];
if(((j>>(y-))&)==((j>>y)&)) continue;
f[x][y][j]+=f[x][y-][j];
}
}
else{
for(int j=;j<bin[m+];++j){
if(!(j&plug1)&&!(j&plug2)) f[x][y][j]=f[x][y-][j];
else f[x][y][j]=;
}
}
}
int main(){
// freopen("testdata.in","r",stdin);
int T=read();
bin[]=;for(int i=;i<=;++i) bin[i]=bin[i-]<<;
for(int t=;t<=T;++t){
n=read(),m=read();
for(int i=;i<=n;++i)
for(int j=;j<=m;++j)
mp[i][j]=read();
memset(f,,sizeof(f));
f[][][]=;
for(int i=;i<=n;++i){
for(int j=;j<=m;++j) solve(i,j);
if(i!=n) for(int j=;j<bin[m];++j)
f[i+][][j<<]=f[i][m][j];
}
printf("Case %d: There are %lld ways to eat the trees.\n",t,f[n][m][]);
}
return ;
}
hdu1693Eat the Trees(插头dp)的更多相关文章
- HDU 1693 Eat the Trees(插头DP)
题目链接 USACO 第6章,第一题是一个插头DP,无奈啊.从头看起,看了好久的陈丹琦的论文,表示木看懂... 大体知道思路之后,还是无法实现代码.. 此题是插头DP最最简单的一个,在一个n*m的棋盘 ...
- hdu1693:eat trees(插头dp)
题目大意: 题目背景竟然是dota!屠夫打到大后期就没用了,,只能去吃树! 给一个n*m的地图,有些格子是不可到达的,要把所有可到达的格子的树都吃完,并且要走回路,求方案数 题解: 这题大概是最简单的 ...
- HDU1693 Eat the Trees 插头dp
原文链接http://www.cnblogs.com/zhouzhendong/p/8433484.html 题目传送门 - HDU1693 题意概括 多回路经过所有格子的方案数. 做法 最基础的插头 ...
- hdu 1693 Eat the Trees——插头DP
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1693 第一道插头 DP ! 直接用二进制数表示状态即可. #include<cstdio> # ...
- HDU 1693 Eat the Trees ——插头DP
[题目分析] 吃树. 直接插头DP,算是一道真正的入门题目. 0/1表示有没有插头 [代码] #include <cstdio> #include <cstring> #inc ...
- HDU1693 Eat the Trees —— 插头DP
题目链接:https://vjudge.net/problem/HDU-1693 Eat the Trees Time Limit: 4000/2000 MS (Java/Others) Mem ...
- 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,画了下图...感觉还是挺有效的... 参考 ...
- 【HDU1693】Eat the Trees(插头dp)
[HDU1693]Eat the Trees(插头dp) 题面 HDU Vjudge 大概就是网格图上有些点不能走,现在要找到若干条不相交的哈密顿回路使得所有格子都恰好被走过一遍. 题解 这题的弱化版 ...
- 【HDU】1693:Eat the Trees【插头DP】
Eat the Trees Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
随机推荐
- mysql服务器启动问题
The server quit without updating PID file (/usr/local/mysql/data/snsgou.pid);可能的情况是启动的用户不对,
- Linux 下搭建 Sonatype Nexus Maven 私服
一.为什么需要搭建mave私服 如果没有私服,我们所需的所有构件都需要通过maven的中央仓库和第三方的Maven仓库下载到本地,而一个团队中的所有人都重复的从maven仓库下 载构件无疑加大了仓库的 ...
- eclipse显示adb is down错误,无法真机调试
cmd进入adb目录下,运行adb kill-server 和 adb start-server还是不能正常调试时, 在360的网络连接列表中找到占用端口5037的adb.exe,全部关闭,重启ecl ...
- 一个商品SKU是怎么生成的
首先说一说什么是SKU.......自己百度去... 类似京东上面,未来人类S5这个台笔记本(没错,我刚入手了) 都是S5这个型号,但是因为CPU,显卡,内存,硬盘等不同,价格也不一样.CPU,显卡, ...
- linux 下 cat
[root@localhost Data]# cat << end > iptable> 3> 4> 5> > 6> end[root@local ...
- Linux学习之路(五)压缩命令
常用压缩格式: .zip .gz .bz2 常用压缩格式: .tar.gz .tar.bz2 .zip格式压缩 .zip 压缩文件名 源文件 #压缩文件 .zip -r 压缩文件名 源目录 #压缩目录 ...
- RQNOJ 329 刘翔!加油!:01背包
题目链接:https://www.rqnoj.cn/problem/329 题意: 刘翔有n封信,每封信都有自己的欣赏价值value[i].消耗时间time[i].消耗体力h[i].和得到的鼓舞w[i ...
- 分享知识-快乐自己:Mybatis缓存机制
论缓存机制: 1):mybatis 提供了缓存机制减轻数据库压力,提高数据库性能. 2):mybatis 的缓存分为两级:一级缓存.二级缓存 3):一级缓存是SqlSession级别的缓存,缓存的数据 ...
- 华为机试 可怕的N阶乘
题目标题: 计算阶乘n!是一件可怕的事情,因为当n并不是很大时,n!将是一个很大的值.例如13! = 6227020800,已经超过了我们常用的unsigned int类型的取值范围.请设计一个程序, ...
- bzoj 2216: Lightning Conductor 单调队列优化dp
题目大意 已知一个长度为\(n\)的序列\(a_1,a_2,...,a_n\)对于每个\(1\leq i\leq n\),找到最小的非负整数\(p\)满足: 对于任意的\(j\), \(a_j \le ...