HDU1693 Eat the Trees(zerojudge a228)
传送门:
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)的更多相关文章
- 2019.01.23 hdu1693 Eat the Trees(轮廓线dp)
传送门 题意简述:给一个有障碍的网格图,问用若干个不相交的回路覆盖所有非障碍格子的方案数. 思路:轮廓线dpdpdp的模板题. 同样是讨论插头的情况,只不过没有前一道题复杂,不懂的看代码吧. 代码: ...
- [Hdu1693]Eat the Trees(插头DP)
Description 题意:在n*m(1<=N, M<=11 )的矩阵中,有些格子有树,没有树的格子不能到达,找一条或多条回路,吃完所有的树,求有多少种方法. Solution 插头DP ...
- 【HDU1693】Eat the Trees(插头dp)
[HDU1693]Eat the Trees(插头dp) 题面 HDU Vjudge 大概就是网格图上有些点不能走,现在要找到若干条不相交的哈密顿回路使得所有格子都恰好被走过一遍. 题解 这题的弱化版 ...
- Eat the Trees(hdu 1693)
题意:在n*m的矩阵中,有些格子有树,没有树的格子不能到达,找一条或多条回路,吃完所有的树,求有多少中方法. 第一道真正意义上的插头DP,可参考陈丹琦的<基于连通性状态压缩的动态规划问题> ...
- HDU 1693 Eat the Trees (插头DP)
题意:给一个n*m的矩阵,为1时代表空格子,为0时代表障碍格子,问如果不经过障碍格子,可以画一至多个圆的话,有多少种方案?(n<12,m<12) 思路: 这题不需要用到最小表示法以及括号表 ...
- HDU1693 Eat the Trees —— 插头DP
题目链接:https://vjudge.net/problem/HDU-1693 Eat the Trees Time Limit: 4000/2000 MS (Java/Others) Mem ...
- 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,入门题)
Problem Description Most of us know that in the game called DotA(Defense of the Ancient), Pudge is a ...
- hdu1693 Eat the Trees [插头DP经典例题]
想当初,我听见大佬们谈起插头DP时,觉得插头DP是个神仙的东西. 某大佬:"考场见到插头DP,直接弃疗." 现在,我终于懂了他们为什么这么说了. 因为-- 插头DP很毒瘤! 为什么 ...
随机推荐
- 微信小程序配置文件记录
最近公司要求,需要研究微信方面的问题,我有幸被选中了,一周时间,研究透做出个小程序来.我就从简单的开始了,记录一下,以后忘了,好来翻阅 app.json 配置文件 配置文件上写:是由哪些页面组成,配置 ...
- msg: ReferenceError: Can't find variable: urchinTracker
在调试的时候发现selenium在启动浏览器打开url地址的时候报这个错误 msg: ReferenceError: Can't find variable: urchinTracker 检查了脚本发 ...
- SQLSERVER 的资源限制
https://docs.microsoft.com/en-us/sql/sql-server/maximum-capacity-specifications-for-sql-server?view= ...
- 微信小程序 功能函数 替换字符串内的指定字符
var str = 'abcadeacf'; var str1 = str.replace('a', 'o'); alert(str1); // 打印结果: obcadeacf var st ...
- HDU4722——Good Numbers——2013 ACM/ICPC Asia Regional Online —— Warmup2
今天比赛做得一个数位dp. 首先声明这个题目在数位dp中间绝对是赤裸裸的水题.毫无技巧可言. 题目的意思是个你a和b,要求出在a和b中间有多少个数满足数位上各个数字的和为10的倍数. 显然定义一个二维 ...
- 内存映像分析工具Eclipse Memory Analyzer
1. Eclipse Memory Analyzer安装 Help ->Eclipse Marketplace,搜索Memory,点击install,->confirm->同意证书内 ...
- 安装pycharm软件后,打开robot framework怎么默认用pycharm打开
1.打开ride.py的属性,修改打开方式
- BZOJ3173 TJOI2013最长上升子序列(splay)
容易发现如果求出最后的序列,只要算一下LIS就好了.序列用平衡树随便搞一下,这里种一棵splay. #include<iostream> #include<cstdio> #i ...
- 洛谷 P1313 计算系数 解题报告
P1313 计算系数 题目描述 给定一个多项式\((by+ax)^k\),请求出多项式展开后\(x^n*y^m\)项的系数. 输入输出格式 输入格式: 共一行,包含5个整数,分别为\(a,b,k,n, ...
- nginx 配置 phpmyadmin
server { listen 8092; server_name *.xxx.com; root /home/users/cuijian04/odp302/app/phpmyadmin; set $ ...