题目大意:

题目背景竟然是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)的更多相关文章

  1. HDU1693 Eat the Trees 插头dp

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

  2. HDU1693 Eat the Trees —— 插头DP

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

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

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

  4. HDU 1693 Eat the Trees(插头DP)

    题目链接 USACO 第6章,第一题是一个插头DP,无奈啊.从头看起,看了好久的陈丹琦的论文,表示木看懂... 大体知道思路之后,还是无法实现代码.. 此题是插头DP最最简单的一个,在一个n*m的棋盘 ...

  5. hdu 1693 Eat the Trees——插头DP

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1693 第一道插头 DP ! 直接用二进制数表示状态即可. #include<cstdio> # ...

  6. HDU 1693 Eat the Trees ——插头DP

    [题目分析] 吃树. 直接插头DP,算是一道真正的入门题目. 0/1表示有没有插头 [代码] #include <cstdio> #include <cstring> #inc ...

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

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

  8. hdu1693 Eat the Trees 【插头dp】

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

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

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

随机推荐

  1. XCode5/Apple LLVM 5.0下使用boost的方法

    Because Apple changes the compiler to llvm only in XCode5, so there are some compatible problems wit ...

  2. Qt Style Sheets Reference

    Qt Style Sheets support various properties, pseudo-states, and subcontrols that make it possible to ...

  3. JAVA实现AES和MD5加密

    package test; import java.io.UnsupportedEncodingException; import java.security.InvalidKeyException; ...

  4. angularjs手动解析表达式($parse)

    <!DOCTYPE html> <html lang="zh-CN" ng-app="app"> <head> <me ...

  5. Atlas mysql的读写分离和负载均衡<转>

    mysql的读写分离和负载均衡 http://my.oschina.net/superbigfu/blog/178134

  6. 【网络流#9】POJ 2135 Farm Tour 最小费用流 - 《挑战程序设计竞赛》例题

    [题意]给出一张无向图,从1开始到n,求两条没有公共边的最短路,使得路程总和最小 每条边的权值设为费用,最大流量设为1,然后就是从源点到汇点流量为2的最小费用流. 因为是规定了流量,新建一个源点和一个 ...

  7. Annotation注解

    概述 Annotation是JDK 5.0以后提供对元数据的支持,可以在编译.加载和运行时被读取,并执行相应的处理.所谓Annotation就是提供了一种为程序元素设置元数据的方法,可用于修饰包.类. ...

  8. hdu 2189

    //hdu2189   题意大概就是给n个人,分成多组,要求每组人数都是素数,求有多少种... 解法就是先把150以内的素数全部存入一个数组,然后利用a[j+b[i]]+=a[j];这道题一开始没理解 ...

  9. 苹果手机button有色差

    input[type=button], input[type=submit], input[type=file], button { cursor: pointer; -webkit-appearan ...

  10. 操作sql - 类型初始值设定项引发异常

    这个异常我还是第一次看见,网上有人说,若出现异常,则访问所有的静态成员,均会抛出异常. 在我碰到的问题中,如下代码: ; static private System.Data.DataTable Re ...