!!!!!!!

第一次学状压DP,其实就是运用位运算来实现一些比较,挺神奇的。。

为什么要发“!!!”因为!x&y和!(x&y)。。感受一下。。

 #include <iostream>
#include <cstdio>
#include <cstring>
#define N 13
#define M 1<<13
#define MOD 1000000000
using namespace std;
int n,m,t,ans;
int so[M],map[M];
int dp[N][M];
bool ju1(int x) {return x&(x<<);}
bool ju2(int x,int y) {return map[x]&so[y];}
int main()
{
while (~scanf("%d%d",&n,&m))
{
memset(map,,sizeof(map));
memset(so,,sizeof(so));
memset(dp,,sizeof(dp));
ans=;
t=;
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
{
int x;
scanf("%d",&x);
if (x==) map[i]+=(<<(j-));
}
for (int i=;i<(<<m);i++)
if (!ju1(i)) so[t++]=i;
for (int i=;i<t;i++)
if (!ju2(,i)) dp[][i]=;
for (int i=;i<=n;i++)
for (int j=;j<t;j++)
{
if (ju2(i,j)) continue;
for (int k=;k<t;k++)
{
if (ju2(i-,k)) continue;
if (!(so[j]&so[k])) dp[i][j]+=dp[i-][k];
}
}
//for (int i=1;i<=n;i++)
//printf("%d\n",t);
for (int j=;j<t;j++)
ans=(ans+dp[n][j])%MOD;
printf("%d\n",ans);
}
return ;
}

Description

Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yummy corn for the cows on a number of squares. Regrettably, some of the squares are infertile and can't be planted. Canny FJ knows that the cows dislike eating close to each other, so when choosing which squares to plant, he avoids choosing squares that are adjacent; no two chosen squares share an edge. He has not yet made the final choice as to which squares to plant.

Being a very open-minded man, Farmer John wants to consider all possible options for how to choose the squares for planting. He is so open-minded that he considers choosing no squares as a valid option! Please help Farmer John determine the number of ways he can choose the squares to plant.

Input

Line 1: Two space-separated integers: M and N 
Lines 2..M+1: Line i+1 describes row i of the pasture with N space-separated integers indicating whether a square is fertile (1 for fertile, 0 for infertile)

Output

Line 1: One integer: the number of ways that FJ can choose the squares modulo 100,000,000.

Sample Input

2 3
1 1 1
0 1 0

Sample Output

9

Hint

Number the squares as follows:

1 2 3
  4  

There are four ways to plant only on one squares (1, 2, 3, or 4), three ways to plant on two squares (13, 14, or 34), 1 way to plant on three squares (134), and one way to plant on no squares. 4+3+1+1=9.

Source

【POJ3254】Corn Fields 状压DP第一次的更多相关文章

  1. POJ 1684 Corn Fields(状压dp)

    描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ ...

  2. POJ 3254 - Corn Fields - [状压DP水题]

    题目链接:http://poj.org/problem?id=3254 Time Limit: 2000MS Memory Limit: 65536K Description Farmer John ...

  3. POJ 3254 Corn Fields (状压dp)

    题目链接:http://poj.org/problem?id=3254 给你n*m的菜地,其中1是可以种菜的,而菜与菜之间不能相邻.问有多少种情况. 状压dp入门题,将可以种菜的状态用一个数的二进制表 ...

  4. [ An Ac a Day ^_^ ] POJ 3254 Corn Fields 状压dp

    题意: 有一块n*m的土地 0代表不肥沃不可以放牛 1代表肥沃可以放牛 且相邻的草地不能同时放牛 问最多有多少种放牛的方法并对1e8取模 思路: 典型的状压dp 能状态压缩 能状态转移 能状态压缩的题 ...

  5. P1879 [USACO06NOV]玉米田Corn Fields 状压dp/插头dp

    正解:状压dp/插头dp 解题报告: 链接! ……我真的太菜了……我以为一个小时前要搞完的题目调错误调了一个小时……90分到100我差不多搞了一个小时…… 然后这题还是做过的……就很气,觉得确实是要搞 ...

  6. [USACO06NOV]玉米田Corn Fields 状压DP

    题面: 农场主John新买了一块长方形的新牧场,这块牧场被划分成M行N列(1 ≤ M ≤ 12; 1 ≤ N ≤ 12),每一格都是一块正方形的土地.John打算在牧场上的某几格里种上美味的草,供他的 ...

  7. [USACO06NOV]玉米田Corn Fields (状压$dp$)

    题目链接 Solution 状压 \(dp\) . \(f[i][j][k]\) 代表前 \(i\) 列中 , 已经安置 \(j\) 块草皮,且最后一位状态为 \(k\) . 同时多记录一个每一列中的 ...

  8. [poj3254]Corn Fields_状压dp

    Corn Fields poj3254 题目大意:给你一个n*m的地,每一块地可以种或不种,两块种过的地不能挨着,可以一块都不种,问所有的种地方案数. 注释:读入用0和1,1<=n,m<= ...

  9. Poj - 3254 Corn Fields (状压DP)(入门)

    题目链接:https://vjudge.net/contest/224636#problem/G 转载于:https://blog.csdn.net/harrypoirot/article/detai ...

随机推荐

  1. fatal: could not read Username for 'https://github.com': No such file or directo

    Git push origin master报错 fatal: could not read Username for 'https://github.com': No such file or di ...

  2. SearchLookUpEdit

    参考资料: 慧都控件网-DevExpress开发资源 在GridControl控件中使用SearchLookUpEdit构建数据快速输入

  3. mysql安装使用笔记

    mysql2008年被sun公司10亿美元收购, 后sun被oracle收购. widenius : 维德纽斯重新写的mysql的分支 mariaDB. 白发程序员, 是由 瑞典mysql AB公司开 ...

  4. PHP的大括号(花括号{})使用详解

    一.不管什么程序,function name(){}, for(){}, ….这太多了,不说也知道什么用了. 二.$str{4}在字符串的变量的后面跟上{}大括号和中括号[]一样都是把某个字符串变量当 ...

  5. iOS开发——高级篇——iOS中常见的设计模式(MVC/单例/委托/观察者)

    关于设计模式这个问题,在网上也找过一些资料,下面是我自己总结的,分享给大家 如果你刚接触设计模式,我们有好消息告诉你!首先,多亏了Cocoa的构建方式,你已经使用了许多的设计模式以及被鼓励的最佳实践. ...

  6. Ubuntu GNOME 16.10 Beta 1问世了!

    导读 Ubuntu GNOME 16.10操作系统已经进入研发周期一段时间了,今天终于可以下载Beta 1版本进行测试了.作为Ubuntu官方flavor之一,Ubuntu GNOME团队非常努力的整 ...

  7. 常用mysql语句

    mysql基本知识:日志文件 =======================================开启/关闭日志修改 /etc/my.cnf #log-bin=mysql-bin #重启my ...

  8. 【转】ubuntu 配置 java jdk1.8 环境,增加多版本 jdk 和切换方法

    一.安装java jdk1.8 1.添加软件源 sudo add-apt-repository ppa:webupd8team/java 2.更新软件源 sudo apt-get update 3.安 ...

  9. Received an invalid response. Origin 'null' is therefore not allowed access

    Received an invalid response. Origin 'null' is therefore not allowed access. 今天在做二级联动,使用ajax请求xml数据, ...

  10. Android开发之---Activity生命周期

    Android开发中,有四大组件:Activity.Service.Content Provider.Broadcast Receiver,可以说,activity的使用是最频繁的了,这里来梳理一下与 ...