题意:给了一个矩阵图,要求使用回路把图中的树全部吃掉的方案树,没有树的点不能走,吃完了这个点也就没有了,走到哪吃到哪

用插头dp搞

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string.h>
using namespace std;
typedef long long LL;
int G[][];
int nrows,ncols;
struct State
{
int up[];
int left;
int encode()const
{
int key=left;
for(int i=; i<ncols; i++)key=key*+up[i];
return key;
}
bool next(int row,int col, int U, int D, int L, int R,State &T)const
{
if(row==nrows- && D!= )return false;
if(col==ncols- && R!= )return false;
int must_left = (col>&&left!=);
int must_up = (row> && up[col]!=);
if( ( must_left!= && L==) || (must_left== && L!=) )return false ;
if( ( must_up != && U== ) || (must_up == && U!= )) return false;
for(int i=; i<ncols; i++)T.up[i]=up[i];
T.up[col]=D;
T.left=R;
return true;
}
};
LL memo[][][<<];
LL rec(int row,int col,const State &S)
{
if(col == ncols ){ col=; row++ ;}
if(row == nrows) return ;
int key=S.encode();
LL &res=memo[row][col][key];
if(res>=)return res;
res=;
State T;
if(G[row][col])
{
if(S.next(row,col,,,,,T))
res+=rec(row,col+,T);
if(S.next(row,col,,,,,T))
res+=rec(row,col+,T);
if(S.next(row,col,,,,,T))
res+=rec(row,col+,T);
if(S.next(row,col,,,,,T))
res+=rec(row,col+,T);
if(S.next(row,col,,,,,T))
res+=rec(row,col+,T);
if(S.next(row,col,,,,,T))
res+=rec(row,col+,T);
}else
{
if(S.next(row,col,,,,,T))
res+=rec(row,col+,T);
}
return res;
}
int main()
{
int cas;
scanf("%d",&cas);
for(int cc=; cc<=cas; cc++)
{
scanf("%d%d",&nrows,&ncols);
for(int i=; i<nrows; i++)
for(int j=; j<ncols ;j++)
scanf("%d",&G[i][j]);
State S;
memset(&S,,sizeof(S));
memset(memo,-,sizeof(memo));
LL ans=rec(,,S);
printf("Case %d: There are %I64d ways to eat the trees.\n",cc,ans);
}
return ;
}

hdu1693 插头dp的更多相关文章

  1. hdu1693插头dp(多回路)

    题意:在n*m的矩阵中,有些格子有树,没有树的格子不能到达,找一条或多条回路,吃全然部的树,求有多少中方法. 这题是插头dp,刚刚学习,不是非常熟悉,研究了好几天才明确插头dp的方法,他们老是讲一些什 ...

  2. [入门向选讲] 插头DP:从零概念到入门 (例题:HDU1693 COGS1283 BZOJ2310 BZOJ2331)

    转载请注明原文地址:http://www.cnblogs.com/LadyLex/p/7326874.html 最近搞了一下插头DP的基础知识……这真的是一种很锻炼人的题型…… 每一道题的状态都不一样 ...

  3. HDU1693 Eat the Trees 插头dp

    原文链接http://www.cnblogs.com/zhouzhendong/p/8433484.html 题目传送门 - HDU1693 题意概括 多回路经过所有格子的方案数. 做法 最基础的插头 ...

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

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

  5. hdu1693 Eat the Trees 【插头dp】

    题目链接 hdu1693 题解 插头\(dp\) 特点:范围小,网格图,连通性 轮廓线:已决策点和未决策点的分界线 插头:存在于网格之间,表示着网格建的信息,此题中表示两个网格间是否连边 状态表示:当 ...

  6. HDU1693 Eat the Trees —— 插头DP

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

  7. hdu1693:eat trees(插头dp)

    题目大意: 题目背景竟然是dota!屠夫打到大后期就没用了,,只能去吃树! 给一个n*m的地图,有些格子是不可到达的,要把所有可到达的格子的树都吃完,并且要走回路,求方案数 题解: 这题大概是最简单的 ...

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

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

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

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

随机推荐

  1. 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习2

    #include <iostream> #include <cctype> using namespace std; const int MAXSIZE=10; int mai ...

  2. css margin使用技巧

    margin使用技巧: (1)设置元素水平居中:margin:x auto; (2)margin负值让元素位移及边框合并 水平居中:auto 代码: <!DOCTYPE html> < ...

  3. List GroupBy真实用法,Reflection(反射)用法,Enum用法,正则,搜索下拉布局

    1.List  GroupBy 用法 var _roomProducts = homesingProducts.GroupBy(t => t.RoomName); RoomedProducts ...

  4. 运用了css,js

    代码如下: <!DOCTYPE html><html xmlns="http://www.w3.org/1999/html"><head> &l ...

  5. Vue使用vue-echarts图表

    vue-echarts和echarts的区别: vue-echarts是封装后的vue插件, 基于 ECharts v4.0.1+ 开发,依赖 Vue.js v2.2.6+,功能一样的只是把它封装成v ...

  6. 版本管理_git

    git 世界上最好的版本管理工具,分布式版本控制系统. 林纳斯-托瓦斯,自由主义教皇(git.linux) git 不管理空文件夹 对比于 SVN mkdir XX        创建一个空目录 XX ...

  7. App测试方法总结

    安全测试   一.安全测试 1.软件权限 1)扣费风险:包括短信.拨打电话.连接网络等. 2)隐私泄露风险:包括访问手机信息.访问联系人信息等. 3)对App的输入有效性校验.认证.授权.数据加密等方 ...

  8. http跳转htts的htaccess文件设置

    RewriteEngine OnRewriteCond %{SERVER_PORT} 80RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]Options ...

  9. Java作业一 (2017-9-10)

    /*程序员龚猛*/ 1.3 public class Helloworld{  public static void main(String[] args) {   System.out.printl ...

  10. springboot整合微软的ad域,采用ldap的api来整合,实现用户登录验证、

    流程: 1.用户调登录接口,传用户名和密码2.用户名和密码在ad验证,验证通过后,返回当前用户的相关信息.(注:ldap为java自带的api不需要maven引入其他的)3.根据返回的用户信息,实现自 ...