hdu1693 插头dp
题意:给了一个矩阵图,要求使用回路把图中的树全部吃掉的方案树,没有树的点不能走,吃完了这个点也就没有了,走到哪吃到哪
用插头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的更多相关文章
- hdu1693插头dp(多回路)
题意:在n*m的矩阵中,有些格子有树,没有树的格子不能到达,找一条或多条回路,吃全然部的树,求有多少中方法. 这题是插头dp,刚刚学习,不是非常熟悉,研究了好几天才明确插头dp的方法,他们老是讲一些什 ...
- [入门向选讲] 插头DP:从零概念到入门 (例题:HDU1693 COGS1283 BZOJ2310 BZOJ2331)
转载请注明原文地址:http://www.cnblogs.com/LadyLex/p/7326874.html 最近搞了一下插头DP的基础知识……这真的是一种很锻炼人的题型…… 每一道题的状态都不一样 ...
- HDU1693 Eat the Trees 插头dp
原文链接http://www.cnblogs.com/zhouzhendong/p/8433484.html 题目传送门 - HDU1693 题意概括 多回路经过所有格子的方案数. 做法 最基础的插头 ...
- 【HDU1693】Eat the Trees(插头dp)
[HDU1693]Eat the Trees(插头dp) 题面 HDU Vjudge 大概就是网格图上有些点不能走,现在要找到若干条不相交的哈密顿回路使得所有格子都恰好被走过一遍. 题解 这题的弱化版 ...
- hdu1693 Eat the Trees 【插头dp】
题目链接 hdu1693 题解 插头\(dp\) 特点:范围小,网格图,连通性 轮廓线:已决策点和未决策点的分界线 插头:存在于网格之间,表示着网格建的信息,此题中表示两个网格间是否连边 状态表示:当 ...
- HDU1693 Eat the Trees —— 插头DP
题目链接:https://vjudge.net/problem/HDU-1693 Eat the Trees Time Limit: 4000/2000 MS (Java/Others) Mem ...
- hdu1693:eat trees(插头dp)
题目大意: 题目背景竟然是dota!屠夫打到大后期就没用了,,只能去吃树! 给一个n*m的地图,有些格子是不可到达的,要把所有可到达的格子的树都吃完,并且要走回路,求方案数 题解: 这题大概是最简单的 ...
- [Hdu1693]Eat the Trees(插头DP)
Description 题意:在n*m(1<=N, M<=11 )的矩阵中,有些格子有树,没有树的格子不能到达,找一条或多条回路,吃完所有的树,求有多少种方法. Solution 插头DP ...
- hdu1693 Eat the Trees [插头DP经典例题]
想当初,我听见大佬们谈起插头DP时,觉得插头DP是个神仙的东西. 某大佬:"考场见到插头DP,直接弃疗." 现在,我终于懂了他们为什么这么说了. 因为-- 插头DP很毒瘤! 为什么 ...
随机推荐
- Git Sever搭建与相关错误处理
搭建 安装git: sudo apt-get install git 创建一个git用户,用来运行git服务:(用自己的用户也可以,其实) sudo adduser git 创建证书登录: 收集所有需 ...
- Java_深度剖析ConcurrentHashMap
本文基于Java 7的源码做剖析. ConcurrentHashMap的目的 多线程环境下,使用Hashmap进行put操作会引起死循环,导致CPU利用率接近100%,所以在并发情况下不能使用Hash ...
- 【循环数组的最大字串和】Maximal-sum Subsequence
[循环数组的最大字串和]Maximal-sum Subsequence PROBLEM 题目描述 给一个 N×N 的矩阵 M,可以取连续的一段数(必须是横着或者竖着或者斜着,这个矩阵是循环的,具体如下 ...
- (63)Wangdao.com第十天_预处理、预解析_函数 上下文对象、参数列表对象
预解析.预处理 1. 在全局代码执行之前,js 引擎 就会创建一个栈来存储管理所有的 执行上下文对象 2. 在 全局执行上下文 window 确定以后,进行压栈 3. 在 函数执行上下文对象 确定以后 ...
- [LeetCode] Card Flipping Game 翻卡片游戏
On a table are N cards, with a positive integer printed on the front and back of each card (possibly ...
- Python基础之语句2
一.if条件语句 1.语法: 2.if语句的真值表达式和条件表达式: 例题1:真值表达式判断奇偶数 num = int(input('请输入一个整数:')) if num % 2 : print('该 ...
- 1.7Oob封装 继承 访问修饰符 静态和构造方法的执行顺序
1:访问修饰符 private 同类中 默认 同类 同包 protect 同类 同包 子类 public 同类 ...
- Cassandra数据模型
Ⅰ.数据模型 1.1 Column 一组包含Name/Value Pair的数据叫Row,其中每一组Name/Value Pair叫Column Column是Cassandra最基本的数据结构,它是 ...
- Apache Arrow
https://www.kdnuggets.com/2017/02/apache-arrow-parquet-columnar-data.html https://arrow.apache.org/ ...
- 二、springboot使用jpa
花了几天时间,好好看了看springboot的jpa部分,总结了常用的形式. 1.通过STS工具添加jpa的依赖项 要连mysql,测试的时候需要web,顺便添加了lombok不写set和get方法了 ...