https://www.luogu.org/problem/show?pid=1879

题目描述

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.

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

遗憾的是,有些土地相当贫瘠,不能用来种草。并且,奶牛们喜欢独占一块草地的感觉,于是John不会选择两块相邻的土地,也就是说,没有哪两块草地有公共边。

John想知道,如果不考虑草地的总块数,那么,一共有多少种种植方案可供他选择?(当然,把新牧场完全荒废也是一种方案)

输入输出格式

输入格式:

第一行:两个整数M和N,用空格隔开。

第2到第M+1行:每行包含N个用空格隔开的整数,描述了每块土地的状态。第i+1行描述了第i行的土地,所有整数均为0或1,是1的话,表示这块土地足够肥沃,0则表示这块土地不适合种草。

输出格式:

一个整数,即牧场分配总方案数除以100,000,000的余数。

输入输出样例

输入样例#1:

2 3
1 1 1
0 1 0
输出样例#1:

9

状压DP
#include<cstdio>
#define mod 1000000000
using namespace std;
int n,m;
int poor[],separate[],cnt,dp[][];
bool not_adjoin_lr(int i)
{
if(i&i<<) return false;
return true;
}
bool not_adjoin_ud(int i,int j)
{
if(i&j) return false;
return true;
}
bool can(int i,int h)
{
if(i&poor[h]) return false;
return true;
}
int main()
{
int x;
scanf("%d%d",&n,&m);
for(int i=;i<n;i++)
for(int j=;j<m;j++)
{
scanf("%d",&x);
if(!x) poor[i+]+=<<j;
}
int tot=<<m;
for(int i=;i<tot;i++)
if(not_adjoin_lr(i))
separate[++cnt]=i;
for(int i=;i<=cnt;i++)
if(can(separate[i],)) dp[][i]=;
for(int i=;i<=n;i++)
{
for(int j=;j<=cnt;j++)
{
if(!can(separate[j],i-)) continue;
for(int k=;k<=cnt;k++)
{
if(!can(separate[k],i)) continue;
if(!not_adjoin_ud(separate[j],separate[k])) continue;
dp[i][k]=(dp[i][k]+dp[i-][j])%mod;
}
}
}
int ans=;
for(int i=;i<=cnt;i++) ans=(ans+dp[n][i])%mod;
printf("%d",ans);
}

[USACO06NOV] Corn Fields的更多相关文章

  1. 状压 DP:[USACO06NOV] Corn Fields,[USACO13NOV] No Change

    [USACO06NOV] Corn Fields (试题来源:Link ) 题目描述 Farmer John has purchased a lush new rectangular pasture ...

  2. 【题解】洛谷P1879 [USACO06NOV] Corn Fields(状压DP)

    洛谷P1879:https://www.luogu.org/problemnew/show/P1879 思路 把题目翻译成人话 在n*m的棋盘 每个格子不是0就是1 1表示可以种 0表示不能种 相邻的 ...

  3. P1879 [USACO06NOV] Corn Fields G

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

  4. P1879 [USACO06NOV]玉米田Corn Fields(状压dp)

    P1879 [USACO06NOV]玉米田Corn Fields 状压dp水题 看到$n,m<=12$,肯定是状压鸭 先筛去所有不合法状态,蓝后用可行的状态跑一次dp就ok了 #include& ...

  5. 状压DP【洛谷P1879】 [USACO06NOV]玉米田Corn Fields

    P1879 [USACO06NOV]玉米田Corn Fields 农场主John新买了一块长方形的新牧场,这块牧场被划分成M行N列(1 ≤ M ≤ 12; 1 ≤ N ≤ 12),每一格都是一块正方形 ...

  6. C++ 洛谷 P1879 [USACO06NOV]玉米田Corn Fields

    没学状压DP的看一下 合法布阵问题  P1879 [USACO06NOV]玉米田Corn Fields 题意:给出一个n行m列的草地(n,m<=12),1表示肥沃,0表示贫瘠,现在要把一些牛放在 ...

  7. 洛谷 P1879 [USACO06NOV]玉米田Corn Fields 题解

    P1879 [USACO06NOV]玉米田Corn Fields 题目描述 Farmer John has purchased a lush new rectangular pasture compo ...

  8. 洛谷P1879 [USACO06NOV]玉米田Corn Fields(状压dp)

    洛谷P1879 [USACO06NOV]玉米田Corn Fields \(f[i][j]\) 表示前 \(i\) 行且第 \(i\) 行状态为 \(j\) 的方案总数.\(j\) 的大小为 \(0 \ ...

  9. USACO Corn Fields

    洛谷 P1879 [USACO06NOV]玉米田Corn Fields 洛谷传送门 题目描述 Farmer John has purchased a lush new rectangular past ...

随机推荐

  1. centos+nginx+redmine+gitosis安装指南

    说明 这篇文章我现在的主要目的是记录自己安装redmine和gitosis的过程,可能写的有些糙,请各位读者见谅.我会在后面的时间里逐渐完善细节.但我想,这已经是网上迄今为止国内最详细的nginx+r ...

  2. POJ 1741 Tree(树的分治)

    Description Give a tree with n vertices,each edge has a length(positive integer less than 1001). Def ...

  3. 常用算法Java实现之冒泡排序

    冒泡排序是所有排序算法中最基本.最简单的一种.思想就是交换排序,通过比较和交换相邻的数据来达到排序的目的. 具体流程如下: 1.对要排序的数组中的数据,依次比较相邻的两个数据的大小. 2.如果前面的数 ...

  4. XDA-University: Getting Started

    XDA-University: Getting Started A while back, we introduced XDA-University to the world, an ongoing ...

  5. .net平台借助第三方推送服务在推送Android,IOS消息(极光推送_V3版本)最新

    最近刚从极光推送官网上看到V2版本要停用,不得不有重新写V3版本的.这里用到了 HTTP Basic Authentication http://www.cnblogs.com/pingming/p/ ...

  6. animate.css与wow.js制作网站动效

    animate.css 官网:https://daneden.github.io/animate.css/ 包括:attention seekers:关注者 bouncing entrances:跳跃 ...

  7. (转)NEST.net Client For Elasticsearch简单应用

    由于最近的一个项目中的搜索部分要用到 Elasticsearch 来实现搜索功能,苦于英文差及该方面的系统性资料不好找,在实现时碰到了不少问题,现把整个处理过程的代码分享下,给同样摸索的人一些借鉴,同 ...

  8. 网页添加提示音,用setInterval

    如果一条数据通过审核了,修改数据库中一个值,用户怎么异步动态知道自己的记录通过审核了呢,我是通过音乐和提示的方式. 网页中添加如下代码: <style> #notify { positio ...

  9. 在Ubuntu系统下编译arcsim仿真器

    首先,用tar zxvf arcsim-0.2.1.tar.gz 将软件包解压 然后,打开里面的INSTALL文件,按照里面的步骤一步一步安装库.Ubuntu13.04下 1.BLAS sudo ap ...

  10. robot framework连接Oracle错误:ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA

    在使用robot framework的关键字Connect to Database Using Custom params连接Oracle数据库: Connect to Database Using ...