题意:

n*m网格1能放0不能放 放的格子不能相邻 求一共多少种可放的方案。

分析:

dp[i][j]第i行可行状态j的的最大方案数,枚举当前行和前一行的所有状态转移就行了(不放牛也算一种情况)

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = 100000000;
int dp[15][5000],n,m,a[15][15];
int judge(int i,int x){
int t=x;
int m1=m;
while(m1--){
if((x&1)&&a[i][m1]==0)
return 0;
x>>=1;
}
if(((t<<1)&t)==0&&((t>>1)&t)==0){
return 1;}
return 0;
}
void solve(){
memset(dp,0,sizeof(dp));
for(int i=0;i<(1<<m);++i){
if(judge(0,i))
dp[0][i]=1;
}
for(int i=1;i<n;++i){
for(int j=0;j<(1<<m);++j){
for(int k=0;k<(1<<m);++k)
if(judge(i,j)&&judge(i-1,k)&&(j&k)==0)
dp[i][j]=(dp[i][j]+dp[i-1][k])%mod;
}
}
int total=0;
for(int i=0;i<(1<<m);++i)
total=(total+dp[n-1][i])%mod;
printf("%d\n",total);
}
int main()
{
while(~scanf("%d%d",&n,&m)){
for(int i=0;i<n;i++)
for(int j=0;j<m;++j)
scanf("%d",&a[i][j]);
solve();
}
return 0;
}

  

Corn Fields(POJ 3254状压dp)的更多相关文章

  1. POJ 3254 (状压DP) Corn Fields

    基础的状压DP,因为是将状态压缩到一个整数中,所以会涉及到很多比较巧妙的位运算. 我们可以先把输入中每行的01压缩成一个整数. 判断一个状态是否有相邻1: 如果 x & (x << ...

  2. poj 3254 状压dp入门题

    1.poj 3254  Corn Fields    状态压缩dp入门题 2.总结:二进制实在巧妙,以前从来没想过可以这样用. 题意:n行m列,1表示肥沃,0表示贫瘠,把牛放在肥沃处,要求所有牛不能相 ...

  3. POJ 3254 状压DP

    题目大意: 一个农民有一片n行m列 的农场   n和m 范围[1,12]  对于每一块土地 ,1代表可以种地,0代表不能种. 因为农夫要种草喂牛,牛吃草不能挨着,所以农夫种菜的每一块都不能有公共边. ...

  4. POJ 3254 状压DP(基础题)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17749   Accepted: 9342 Desc ...

  5. Corn Fields POJ - 3254 (状压dp)

    题目链接: Corn Fields  POJ - 3254 题目大意:给你一个n*m的矩阵,矩阵的元素只包括0和1,0代表当前的位置不能放置人,1代表当前的位置可以放人,当你决定放人的时候,这个人的四 ...

  6. hdu 3254 (状压DP) Corn Fields

    poj 3254 n乘m的矩阵,1表示这块区域可以放牛,0,表示不能,而且不能在相邻的(包括上下相邻)两个区域放牛,问有多少种放牛的方法,全部不放也是一种方法. 对于每块可以放牛的区域,有放或者不放两 ...

  7. poj 1170状压dp

    题目链接:https://vjudge.net/problem/POJ-1170 题意:输入n,表示有那种物品,接下来n行,每行a,b,c三个变量,a表示物品种类,b是物品数量,c代表物品的单价.接下 ...

  8. POJ 2411 状压DP经典

    Mondriaan's Dream Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 16771   Accepted: 968 ...

  9. poj 1185(状压dp)

    题目链接:http://poj.org/problem?id=1185 思路:状态压缩经典题目,dp[i][j][k]表示第i行状态为j,(i-1)行状态为k时最多可以放置的士兵个数,于是我们可以得到 ...

随机推荐

  1. POJ3009Curling 2.0

    http://poj.org/problem?id=3009 题意 : 迷宫升级版,也是m*n的迷宫,0是可以走的,1是阻塞,2是初始点,3是目标位置,这个的阻塞是可以消除的,就是说只要石头撞到阻塞, ...

  2. VBScript 函数

    Date/Time 函数 Conversion 函数 Format 函数 Math 函数 Array 函数 String 函数 其他函数 Date/Time 函数 函数 描述 CDate 把一个有效的 ...

  3. 李洪强漫谈iOS开发[C语言-010] - C语言简要复习

    // //  main.m //  05 - 简要复习 // //  Created by vic fan on 16/7/13. //  Copyright © 2016年 李洪强. All rig ...

  4. 什么是spring?

    一.对spring的理解. 1.Spring是实现了工厂模式的工厂类(什么是工厂类?简单的来说就是把需要的接口定义到一个类中,需要的时候不用新建,直接从这个类中调用该接口就可以了), 这个类的名字为B ...

  5. eclipse安装反编译插件

    1. 进入http://jadclipse.sourceforge.net/wiki/index.php/Main_Page#Download          下载 net.sf.jadclipse ...

  6. Android:调试之DDMS

    DDMS 的全称是Dalvik Debug Monitor Service,是 Android 开发环境中的Dalvik虚拟机调试监控服务. 在Eclipse,项目启动了虚拟器后,右上角选择Open ...

  7. Jdk命令之jps

    jps -- Java Virtual Machine Process Status Tool jps命令类似于Linux下的ps命令,可以列出本机所有正在运行的java进程.

  8. chmod u+x 脚本文件

    [root@ossec-server Shell]# chmod u+x whologged.sh解释: chmod:改变权限 u:文件所有用户 +x: 增加可执行权限 [root@ossec-ser ...

  9. SQL Server查询优化方法(查询速度慢的原因很多,常见如下几种) .

    今天看到一位博友的文章,觉得不错,转载一下,希望对大家有帮助,更多文章,请访问:http://blog.haoitsoft.com 1.没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺 ...

  10. SoapUI test WCF

    http://blogs.msdn.com/b/nabeelp/archive/2008/03/07/obscure-error-addressfilter-mismatch-at-the-endpo ...