hdu1693:eat trees(插头dp)
题目大意:
题目背景竟然是dota!屠夫打到大后期就没用了,,只能去吃树!
给一个n*m的地图,有些格子是不可到达的,要把所有可到达的格子的树都吃完,并且要走回路,求方案数
题解:
这题大概是最简单的插头dp了。。
比陈丹琦论文里的例题还要简单,因为允许有多个回路,所以不需要存储插头之间的连通性,直接二进制状压
搞清楚插头和轮廓线的概念基本就可以做出来了
这里有一些资料http://www.docin.com/p-741918386.html
代码:
#include <iostream>
#include <stdio.h>
#include<string.h>
#include<algorithm>
#include<string>
#include<ctype.h>
using namespace std;
#define MAXN 10000
long long dp[][][<<];
int g[][];
int n,m;
int main()
{
int t,cas=;
scanf("%d",&t);
while(t--)
{
cas++;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
scanf("%d",g[i]+j);
}
}
memset(dp,,sizeof(dp));
dp[][m][]=;
for(int i=;i<=n;i++)
{
for(int j=;j<(<<m);j++)
{
dp[i][][j<<]=dp[i-][m][j];
}
for(int j=;j<=m;j++)
{
for(int k=;k<(<<(m+));k++)
{
int u=<<j;
int l=<<(j-);
if(g[i][j]==)
{
if((!(k&u))&&(!(k&l)))
dp[i][j][k]=dp[i][j-][k];
continue;
}
if((k&u)&&(k&l))
{
dp[i][j][k-u-l]+=dp[i][j-][k];
}
if((k&u)&&(!(k&l)))
{
dp[i][j][k]+=dp[i][j-][k];
dp[i][j][k-u+l]+=dp[i][j-][k];
}
if((k&l)&&(!(k&u)))
{
dp[i][j][k]+=dp[i][j-][k];
dp[i][j][k-l+u]+=dp[i][j-][k];
}
if((!(k&u))&&(!(k&l)))
{
dp[i][j][k+u+l]+=dp[i][j-][k];
}
}
}
}
printf("Case %d: There are %I64d ways to eat the trees.\n",cas,dp[n][m][]);
}
return ;
}
hdu1693:eat trees(插头dp)的更多相关文章
- HDU1693 Eat the Trees 插头dp
原文链接http://www.cnblogs.com/zhouzhendong/p/8433484.html 题目传送门 - HDU1693 题意概括 多回路经过所有格子的方案数. 做法 最基础的插头 ...
- 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)
题目链接 USACO 第6章,第一题是一个插头DP,无奈啊.从头看起,看了好久的陈丹琦的论文,表示木看懂... 大体知道思路之后,还是无法实现代码.. 此题是插头DP最最简单的一个,在一个n*m的棋盘 ...
- 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)
[HDU1693]Eat the Trees(插头dp) 题面 HDU Vjudge 大概就是网格图上有些点不能走,现在要找到若干条不相交的哈密顿回路使得所有格子都恰好被走过一遍. 题解 这题的弱化版 ...
- hdu1693 Eat the Trees 【插头dp】
题目链接 hdu1693 题解 插头\(dp\) 特点:范围小,网格图,连通性 轮廓线:已决策点和未决策点的分界线 插头:存在于网格之间,表示着网格建的信息,此题中表示两个网格间是否连边 状态表示:当 ...
- [Hdu1693]Eat the Trees(插头DP)
Description 题意:在n*m(1<=N, M<=11 )的矩阵中,有些格子有树,没有树的格子不能到达,找一条或多条回路,吃完所有的树,求有多少种方法. Solution 插头DP ...
随机推荐
- [Javascript] Array methods in depth - slice
Array slice creates a shallow copy of an array. In this lesson we cover, in detail, exactly what a ' ...
- 拿到手机ip住址
转载自:http://blog.csdn.net/showhilllee/article/details/8746114 貌似ASI里获取ip地址的链接不能够了.也曾试过whatismyip,在其站点 ...
- Android TabActivity之感叹
(一)前言 在以前一篇帖子讲ams的时候,提了一下TabActivity.当时说它比较特殊就没有下文了,今天重发一篇帖子,跟大家探讨一下TabActivity. 做个假定先: 比如我们最外面的Acti ...
- 《C专家编程》之一
一.解决函数返回指针的几种方法 1. 返回一个指向字符串常量的指针. 例子: char* func() { rturn "Only work for simple strings" ...
- PHP 将Base64图片保存到 Sae storage
<?php $file_dir='tu/'.date("Y/m/d").'/'; $fileName=create_guid(); $storage = new SaeSto ...
- Spark HA 的搭建
接hadoop HA的搭建,因为你zookeeper已经部署完成,所以直接安装spark就可以 tar –xzf spark-1.6.1-bin-hadoop2.6.tgz -C ../service ...
- POJ 1556 The Doors 线段判交+Dijkstra
The Doors Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6734 Accepted: 2670 Descrip ...
- mui实现支付宝支付功能
<!DOCTYPE html><html> <head> <meta charset="utf-8"> <title>H ...
- python面对对象编程----2:__init__
面对对象编程估计我们最早接触到的就是__init__了,也就是实例的初始化处理过程: 1:来看看最基础的__init__ class Card(object): #抽象类Card,并不用于实例化 de ...
- Hyper-V虚拟机和主机的网络配置
Hyper-V虚拟机和主机的网络配置 方式1.共享式 这种方式是将Hyper-V内部的虚拟网络与外部网络共享.使得内部是一个私有的网络.属于NAT的类型.(不知道这么说对不对) 优点: 相对来说属于私 ...