luogu P1879 [USACO06NOV]玉米田Corn Fields
题目描述
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的余数。
输入输出样例
2 3
1 1 1
0 1 0
9
i
装压dp,1A,爽,dp[i][j]表示选取到地i行,上一行的状态是j
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
#define mod 100000000
inline int read() {
int x=,f=;
char c=getchar();
while(c<''||c>'') {
if(c=='-') f=-;
c=getchar();
}
while(c<=''&&c>='') {
x=x*+c-'';
c=getchar();
}
return x;
}
#define maxn 14
int map[maxn][maxn];
int b[maxn];
int no[maxn],dp[][<<];
int main() {
n=read(),m=read();
for(int i=;i<n;++i) {
for(int x,j=;j<m;++j) {
x=read();
if(x)b[i]|=(<<(j));
}
}
int num=(<<m);
for(int i=;i<num;++i)if(((b[]&i)==i)&&(!(i&(i>>))&&!(i&i<<)))dp[][i]=;
for(int i=;i<n;++i) {
for(int j=;j<num;++j) {
if(((b[i]&j)==j)&&(!(j&(j>>))&&!(j&j<<))) {
for(int k=;k<num;++k){
if(!(j&k)) {
dp[i][j]=(dp[i][j]+dp[i-][k])%mod;
}
}
}
}
}
int ans=;
for(int i=;i<num;++i) {
ans=(ans+dp[n-][i])%mod;
}
printf("%d\n",ans);
return ;
}
luogu P1879 [USACO06NOV]玉米田Corn Fields的更多相关文章
- 【luogu P1879 [USACO06NOV]玉米田Corn Fields】 题解
题目链接:https://www.luogu.org/problemnew/show/P1879 状压DP. 设dp[i][j]表示第i行,状态为j的方案数 初始dp[0][0] = 1 这样一共12 ...
- P1879 [USACO06NOV]玉米田Corn Fields(状压dp)
P1879 [USACO06NOV]玉米田Corn Fields 状压dp水题 看到$n,m<=12$,肯定是状压鸭 先筛去所有不合法状态,蓝后用可行的状态跑一次dp就ok了 #include& ...
- C++ 洛谷 P1879 [USACO06NOV]玉米田Corn Fields
没学状压DP的看一下 合法布阵问题 P1879 [USACO06NOV]玉米田Corn Fields 题意:给出一个n行m列的草地(n,m<=12),1表示肥沃,0表示贫瘠,现在要把一些牛放在 ...
- 洛谷 P1879 [USACO06NOV]玉米田Corn Fields 题解
P1879 [USACO06NOV]玉米田Corn Fields 题目描述 Farmer John has purchased a lush new rectangular pasture compo ...
- 洛谷P1879 [USACO06NOV]玉米田Corn Fields(状压dp)
洛谷P1879 [USACO06NOV]玉米田Corn Fields \(f[i][j]\) 表示前 \(i\) 行且第 \(i\) 行状态为 \(j\) 的方案总数.\(j\) 的大小为 \(0 \ ...
- P1879 [USACO06NOV]玉米田Corn Fields (状压dp入门)
题目链接: https://www.luogu.org/problemnew/show/P1879 具体思路: 我们可以先把所有合法的情况枚举出来,然后对第一行判断有多少种情况满足,然后对于剩下的行数 ...
- 洛谷P1879 [USACO06NOV]玉米田Corn Fields (状态压缩DP)
题目描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ...
- P1879 [USACO06NOV]玉米田Corn Fields
题目描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ...
- 洛谷P1879 [USACO06NOV]玉米田Corn Fields【状压DP】题解+AC代码
题目描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ...
随机推荐
- JAVA基础篇—抽象类,抽象方法
class Shape package com.shape; public abstract class Shape { double area;// double per;// String col ...
- POJ:1328-Radar Installation
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Description Assume the coasting is an inf ...
- Python之code对象与pyc文件(二)
上一节:Python之code对象与pyc文件(一) 创建pyc文件的具体过程 前面我们提到,Python在通过import或from xxx import xxx时会对module进行动态加载,如果 ...
- LOFTER 迁移
title: LOFTER 迁移 date: 2018-09-01 16:41:02 updated: tags: [其他] description: keywords: comments: imag ...
- ogre的初始化与启动以及显示对象设置
ogre的使用方法1---自动设置 1.ogre初始化:首先实例化一个Root对象 Root * root = new Root(); Root * root = new Root("plu ...
- c中#与##的应用思考
c中#与##的应用思考 原创 2014年02月25日 22:01:35 927 一. 思考出处 在读<<linux 0.12完全剖析>>初始化部分, init进程是通过fork ...
- C++ POST方式访问网页
bool PostContent(CString strUrl, const CString &strPara, CString &strContent, CString &s ...
- 2015长春网络赛1001 求连通快数量的问题dfs
Ponds Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Sub ...
- hdu6097[二分+解析几何] 2017多校6
/*hdu6097[二分+解析几何] 2017多校6*/ #include <bits/stdc++.h> using namespace std; ; struct node{ doub ...
- NOJ——1658平方和(自然数平方和公式和取模法则)
[1658] 平方和 时间限制: 1000 ms 内存限制: 65535 K 问题描述 给你两个数n和m,求从6开始到6*n的等差数列(差值为6)的每一项的平方的和除6模m的值 (例如n=2,m=3, ...