poj3254 Corn Fields
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 17989 | Accepted: 9474 |
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
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
Sample Input
2 3
1 1 1
0 1 0
Sample Output
9
Hint
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.
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int mod = ;
int n,m,a[][],f[][ << ],cnt[],maxn,ans,sta[ << ],tot; bool check(int x,int y)
{
if (x & y)
return false;
return true;
} int main()
{
scanf("%d%d",&n,&m);
maxn = ( << m) - ;
for (int i = ; i <= maxn; i++)
{
if (i & (i << ))
continue;
sta[++tot] = i;
}
for (int i = ; i <= n; i++)
for (int j = ; j <= m; j++)
{
scanf("%d",&a[i][j]);
if (a[i][j] == )
cnt[i] |= ( << (m - j));
}
for (int i = ; i <= tot; i++)
if (check(cnt[],sta[i]))
f[][sta[i]] = ;
for (int i = ; i <= n; i++)
for (int j = ; j <= tot; j++)
{
if (!check(cnt[i - ],sta[j]))
continue;
for (int k = ; k <= tot; k++)
{
if (!check(cnt[i],sta[k]))
continue;
if (sta[k] & sta[j])
continue;
f[i][sta[k]] += f[i - ][sta[j]];
f[i][sta[k]] %= mod;
}
}
for (int i = ; i <= tot; i++)
{
ans += f[n][sta[i]];
ans %= mod;
}
printf("%d\n",ans); return ;
}
poj3254 Corn Fields的更多相关文章
- poj3254 Corn Fields 利用状态压缩求方案数;
Corn Fields 2015-11-25 13:42:33 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10658 ...
- poj3254 Corn Fields (状压DP)
http://poj.org/problem?id=3254 Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissio ...
- POJ3254 Corn Fields(状压DP)
题目给个n×m的地图,1可以放玉米0不可以,现在要放玉米,玉米上下左右不能相邻,问放法有几种. 当前一行的决策只会影响下一行,所以状压DP之: dp[i][S]表示前i行放完且第i行放玉米的列的集合是 ...
- POJ 3254 poj3254 Corn Fields
题意:给出一个n行m列的草地,1表示肥沃,0表示贫瘠,现在要把一些牛放在肥沃的草地上,但是要求所有牛不能相邻,问你有多少种放法. 思路: DP[i][j]=sum(dp[i-1][k]); i表示当前 ...
- POJ3254 - Corn Fields(状态压缩DP)
题目大意 给定一个N*M大小的土地,土地有肥沃和贫瘠之分(每个单位土地用0,1来表示贫瘠和肥沃),要求你在肥沃的单位土地上种玉米,如果在某个单位土地上种了玉米,那么与它相邻的四个单位土地是不允许种玉米 ...
- 【状压DP】poj3254 Corn Fields
题意: 一块n*m的田,1表示这个地方可以种植,0代表这个地方不能种植.植物种植还必须满足两株植物不能相邻(横竖都不行).问共有几种种植方法,而且当什么都不种时认为是一种方法. 解题思路: 种植用1表 ...
- 【原创】【状态压缩DP】POJ3254 Corn Fields【新手向】
一开始根本不会状压dp,上网各种找题解,但发现他们写的都很......反正我作为一个没有接触过状态压缩的,根本看不懂! 然后看了好多状态压缩的题的题解,总结了一下思路,思路很重要,有了思路转换成计算机 ...
- 【状压基础题】poj3254 Corn Fields
题目大意 :农夫约翰有n*m块地,其中一些地荒掉了.玉米是一种傲娇的植物,种在相邻的地里会导致不孕不育.求所有种法数对100000000求余. 读入:第一行一个n一个m, 接下来是一个n行m列的矩形, ...
- Corn Fields——POJ3254状态压缩Dp
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Description Farmer John has purchased a lush new ...
随机推荐
- TW实习日记:第五天
今天可以说是非常忙的一天了,要再项目中实现微信相关的功能:授权登录以及扫码登录,还有就是自建应用的发送消息.首先功能代码其实在经过了几天的学习之后并没有很难,但是最让我难受的是在项目中去加代码,首先s ...
- Hbase 教程-安装
HBase安装 安装前设置 安装Hadoop在Linux环境下之前,需要建立和使用Linux SSH(安全Shell).按照下面设立Linux环境提供的步骤. 创建一个用户 首先,建议从Unix创建一 ...
- kafka相关文章引用
kafka相关内容说明: Kafka压缩 Kafka端到端审计 kafka数据可靠性深度解读 Kafka发送超过broker限定大小的消息时Client和Broker端各自会有什么异常? Kafka之 ...
- springboot 集成 swagger
1. 首先配置swaggerConfigpackage com.lixcx.lismservice.config; import com.lixcx.lismservice.format.Custom ...
- nginx配置 send_timeout 引发的js、css解析失败问题
错误情况是web界面排版错误,js.css文件加载失败,通过调试器查看js和css文件路径都是对的,而且可访问. 业务使用的是 nginx+php+mysql+redis的架构 解决办法: 查了很多资 ...
- scrum立会报告+燃尽图(第三周第二次)
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2284 项目地址:https://coding.net/u/wuyy694 ...
- C#从一个窗体传递参数到另一个窗体的链接
http://blog.sina.com.cn/s/blog_60d69ce00100eldt.html
- 3dContactPointAnnotationTool开发日志(二九)
今天想着在Windows平台上跑通那个代码,不过它的官网上写的支持平台不包括windows,但我还是想试试,因为看他的依赖好像和平台的关系不是特别大. 看了下它的py代码,不知道是py2还是p ...
- 软工网络15团队作业4-DAY3
昨天的工作. 张陈东芳:数据库连接的检查 吴敏烽:商品实体类的检查 周汉麟:继续研究获取商品信息方法的方法和调试 林振斌:继续研究获取商品信息方法的方法和调试 李智:Cookies的检查 全体人员:优 ...
- gulp 定义依赖关系
var gulp = require('gulp'); // 返回一个 callback,因此系统可以知道它什么时候完成 gulp.task('one', function(cb) { // 做一些事 ...