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

用插头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. python 函数split()

    函数:split() Python中有split()和os.path.split()两个函数,具体作用如下:split():拆分字符串.通过指定分隔符对字符串进行切片,并返回分割后的字符串列表(lis ...

  2. 新浪实时股票数据接口http://hq.sinajs.cn/list=股票代码

    股票数据的获取目前有如下两种方法可以获取: 1. http/JavaScript接口取数据 2. web-service接口 1.http/JavaScript接口取数据1.1Sina股票数据接口以大 ...

  3. (90)Wangdao.com第二十三天_JavaScript CSS 操作

    CSS 操作 通过 JavaScript 操作 CSS HTML 元素的 style 属性 <div style="background-color:red; border:1px s ...

  4. [LeetCode] Insert into a Cyclic Sorted List 在循环有序的链表中插入结点

    Given a node from a cyclic linked list which is sorted in ascending order, write a function to inser ...

  5. Docker简介以及使用docker搭建lnmp的过程(多PHP版本)

    一.Docker基础 Docker安装 Docker 要求 Ubuntu 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的 Ubuntu 版本是否支持 Docker. 通过 uname ...

  6. ldd可执行程序时返回not a dynamic executable

    原因:32位程序放在64位机器上或64位程序放在32位程序上了 解决方法:如果是32位程序放在64位系统上则安装yum -y install libstdc++.i686,64位则是yum -y in ...

  7. php中数组直接用加号相加array+array

    php中数组功能非常强大,甚至也可以直接通过+相加来合并数组. A数组 $a = ['a', 'b']; B数组 $b = ['c', 'd', 'e']; A+B结果 Array ( [0] =&g ...

  8. nginx匹配规则说明以及匹配的优先级

    location 匹配规则语法规则 location [=|~|~*|^~] /uri/ { … } 模式    含义location = /uri    = 表示精确匹配,只有完全匹配上才能生效lo ...

  9. rabbit_mq实现分布式事务

    gitlab下载地址: 一.rabbitmq实现原理 一般在自己内部系统中建议采用lcn刚性事务来处理,面对调用第三方接口,或者夸平台语言是采用消息中间来实现补偿型事务.注意在进行补偿时需要注意重复调 ...

  10. linux软件安装方式

    先插句题外话,快捷键 Ctrl+s 的功能是停止输入,Ctrl+q 恢复输入; 正题,在linux的应用软件安装有三种: 1,tar包 2,rpm包 3,dpkg包 以下介绍三种包的安装和卸载方式 1 ...