USACO 2006 November Gold Corn Fields
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的更多相关文章
- USACO 2006 November Gold Corn Fields /// 状压 oj23941
题目大意: 输入n m 接下来n行m列 0表示不能种玉米 1表示能 要求种玉米位置的上下左右四连通区域不能种玉米 输出方案数 Sample Input 2 31 1 10 1 0 Sample Out ...
- USACO 2006 November Gold
POJ 3253 Fence Repair STL堆操作 我想说,STL里堆是我目前见到最蛋疼的操作. #include <cstdio> #include <cstring> ...
- 【USACO 2006 November Gold】Corn Fields
[题目链接] 点击打开链接 [算法] 状压DP [代码] #include<bits/stdc++.h> using namespace std; #define MAXN 12 #def ...
- USACO 2006 November Gold Fence Repair /// 贪心(有意思)(优先队列) oj23940
题目大意: 输入N ( 1 ≤ N ≤ 20,000 ) :将一块木板分为n块 每次切割木板的开销为这块木板的长度,即将长度为21的木板分为13和8,则开销为21 接下来n行描述每块木板要求的长度Li ...
- 【usaco 2006 feb gold】 牛棚安排
终于自己独立做出来一道题QAQ然而本校数据实在太水不能确定我是不是写对了... 原题: Farmer John的N(1<=N<=1000)头奶牛分别居住在农场所拥有的B(1<=B&l ...
- [Poj3261] [Bzoj1717] [后缀数组论文例题,USACO 2006 December Gold] Milk Patterns [后缀数组可重叠的k次最长重复子串]
和上一题(POJ1743,上一篇博客)相似,只是二分的判断条件是:是否存在一段后缀的个数不小于k #include <iostream> #include <algorithm> ...
- USACO 2008 November Gold Cheering up the Cows /// MST oj24381
题目大意: 输入n,p:n个点,p条路 接下来n行输入c[]:在各个点需要花费的时间 接下来p行输入u,v,w:u点到v点的路需要花费时间w 求经过所有点且最后回到起点的最少花费时间 https:// ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- poj 3254 Corn Fields
http://poj.org/problem?id=3254 Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissio ...
随机推荐
- MyBatis系列:二、配置文件详解
本文会详细介绍MyBatis的常用配置 1.properties节点 <properties resource="mybatis-config.properties"> ...
- drop_duplicates()函数
1dataframe删除某一列的重复元素,默认只留下第一次出现的 inplace参数设置为true时直接在原数据上修改,为False时,生成副本. 注意所有函数中inplace一旦设置为True,此时 ...
- UI自动化之8种基础定位
UI自动化的核心在于定位 目录 1.8种基础定位方法 2.xpath定位 3.css定位 4.多组元素 1.8种基础定位方法 driver.find_element_by_id() #id定位 dri ...
- GUI_FlowLayout
void setBounds(x, y, width, height) 设置窗体坐标,窗体大小 import java.awt.Frame; public class IntegerDemo { pu ...
- Leaflet
https://leafletjs.com/ https://github.com/Leaflet/Leaflet
- python程序的模块与包
python的程序是由模块组成的,一个python文件就是一个模块,而模块一般由代码,函数,或者类组成.创建baiduHq.py模块(文件),在该模块中编写变量,函数,类,来说明在一个模块中,变量的输 ...
- [Python3 填坑] 010 isalpha() 对于字母的定义
目录 1. print( 坑的信息 ) 2. 开始填坑 官方文档 1. print( 坑的信息 ) 挖坑时间:2019/01/14 明细 坑的编码 内容 Py009-1 isalpha() 理当只有输 ...
- Balanced Lineup poj3264 线段树
Balanced Lineup poj3264 线段树 题意 一串数,求出某个区间的最大值和最小值之间的差 解题思路 使用线段树,来维护最大值和最小值,使用两个查询函数,一个查区间最大值,一个查区间最 ...
- Codeforces 429E(欧拉回路)
题面 传送门 题目大意: 有n条线段,每条线段染红色或蓝色,使得数轴上每个点被红色线段覆盖的次数与被蓝色线段覆盖数差的绝对值小于等于1.输出染色方案. 分析 题意其实可以这样理解: 一段初始全为0 的 ...
- 面向切面编程 AOP 和装饰器??
1.AOP概念:面向切面编程,指扩展功能不修改源代码,将功能代码从业务逻辑代码中分离出来. 主要功能:日志记录,性能统计,安全控制,事务处理,异常处理等等. 主要意图:将日志记录,性能统计,安全控制, ...