USACO 2006 November Gold Corn Fields

题目描述:

Farmer John has purchased a lush new rectangular pasture composed of M by N 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.

输入格式:

* 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)

输出格式:

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

样例输入:

2 3
1 1 1
0 1 0

样例输出:

9

提示:

【样例解释】

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.

【数据规模】

1<=M<=12;1<=N<=12

时间限制:1000ms
空间限制:256MByte

又水了一道题,地图记得反着存就好了。。。别忘了%%%kcz!!!

唉,最近kcz在玩pku的游戏挑战赛,我们这些小蒟蒻只有刷水题的份了,QAQ——

#include<bits/stdc++.h>
#define ll long long
#define kcz 100000000
using namespace std; ll f[][ << ] , m , n , maxn;
ll s [][]; ll check(ll now , ll down)
{
if((down << ) & down || (down >> ) & down) return ;
for(ll i=;i<m;i++)
{
ll ce = << i;
if(now & ce && down & ce) return ;
}
return ;
} ll find(ll pos , ll val)
{
for(ll i=;i<m;i++)
{
ll ce = << i;
if(val & ce && s[pos][i]) return ;
}
return ;
} int main(){
cin >> n >> m;
for(ll i=;i<=n;i++)
for(ll j=;j<m;j++)
{ scanf("%lld",&s[i][j]);
s[i][j] ^= ;
}
maxn = << m;
f[][] = ;
for(ll i=;i<n;i++)
for(ll j=;j<maxn;j++)
{
if(f[i][j])
{
for(ll k=;k<maxn;k++)
if(check(j , k) && find(i + , k))
f[i + ][k] += f[i][j];
}
}
ll ans = ;
for(ll i=;i<maxn;i++)
{
ans += f[n][i];
ans %= kcz;
}
cout << ans;
}

USACO 2006 November Gold Corn Fields的更多相关文章

  1. USACO 2006 November Gold Corn Fields /// 状压 oj23941

    题目大意: 输入n m 接下来n行m列 0表示不能种玉米 1表示能 要求种玉米位置的上下左右四连通区域不能种玉米 输出方案数 Sample Input 2 31 1 10 1 0 Sample Out ...

  2. USACO 2006 November Gold

    POJ 3253 Fence Repair STL堆操作 我想说,STL里堆是我目前见到最蛋疼的操作. #include <cstdio> #include <cstring> ...

  3. 【USACO 2006 November Gold】Corn Fields

    [题目链接] 点击打开链接 [算法] 状压DP [代码] #include<bits/stdc++.h> using namespace std; #define MAXN 12 #def ...

  4. USACO 2006 November Gold Fence Repair /// 贪心(有意思)(优先队列) oj23940

    题目大意: 输入N ( 1 ≤ N ≤ 20,000 ) :将一块木板分为n块 每次切割木板的开销为这块木板的长度,即将长度为21的木板分为13和8,则开销为21 接下来n行描述每块木板要求的长度Li ...

  5. 【usaco 2006 feb gold】 牛棚安排

    终于自己独立做出来一道题QAQ然而本校数据实在太水不能确定我是不是写对了... 原题: Farmer John的N(1<=N<=1000)头奶牛分别居住在农场所拥有的B(1<=B&l ...

  6. [Poj3261] [Bzoj1717] [后缀数组论文例题,USACO 2006 December Gold] Milk Patterns [后缀数组可重叠的k次最长重复子串]

    和上一题(POJ1743,上一篇博客)相似,只是二分的判断条件是:是否存在一段后缀的个数不小于k #include <iostream> #include <algorithm> ...

  7. USACO 2008 November Gold Cheering up the Cows /// MST oj24381

    题目大意: 输入n,p:n个点,p条路 接下来n行输入c[]:在各个点需要花费的时间 接下来p行输入u,v,w:u点到v点的路需要花费时间w 求经过所有点且最后回到起点的最少花费时间 https:// ...

  8. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  9. poj 3254 Corn Fields

    http://poj.org/problem?id=3254 Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissio ...

随机推荐

  1. C# datatable 导出到Excel

    datatable导出到Excel /// <summary> /// 将DataTable导出为Excel文件(.xls) /// </summary> /// <pa ...

  2. 16/7/7_PHP-面向对象关键词

    转载地址: http://blog.sina.com.cn/s/blog_5182b171010092fb.html PHP5 是一具备了大部分面向对象语言的特性的语言,比PHP4 有了很多的面向对象 ...

  3. [Git] 004 初识 Git 与 GitHub 之查看历史记录

    在 GitHub 的 UI 界面使用 Git 查看历史纪录 1. 右侧有个 history 2. 点击后跳转页面 3. 点击相应标题(commit 时写的),进入相应版本(历史) 4. 我选择了 I ...

  4. Java-多线程第四篇线程池

    1.什么是线程池. 线程池在系统启动的时候即创建大量的空闲的线程,程序将一个Runnable对象或者Callable对象传给线程池,线程池就会启动一个线程来执行它们的run()或者call()方法,当 ...

  5. Java包的使用

    好处 1.类似于文件系统的文件夹,可以实现分类管理类文件,方便查找2.解决了同一个项目中同名类的冲突问题 包的创建 命名规范: 建议小写字母,并且采用域名倒置的写法 域名倒置:com.baidu ww ...

  6. hive Hbase sql

    Hive和HBase的区别 ​ hive是为了简化编写MapReduce程序而生的,使用MapReduce做过数据分析的人都知道,很多分析程序除业务逻辑不同外,程序流程基本一样.在这种情况下,就需要h ...

  7. Balanced Lineup poj3264 线段树

    Balanced Lineup poj3264 线段树 题意 一串数,求出某个区间的最大值和最小值之间的差 解题思路 使用线段树,来维护最大值和最小值,使用两个查询函数,一个查区间最大值,一个查区间最 ...

  8. 1.go语言目录结构

    [root@localhost ~]# ll /go/ total drwxr-xr-x. root root May : api -rw-r--r--. root root May : AUTHOR ...

  9. SQL中的like '%%‘查询

    一,我们正常使用like时,这是有两个条件的模糊查询 select *From Test where UserName like '%m%' and UserName like '%a%' 二,但这时 ...

  10. js中的函数声明置顶

    函数声明置顶是指 js引擎在读取变量与声明式函数时,会优先读取,例如如下 var a = 1: function a(){}; console.log(a); //这里得到的为1,而不是该functi ...