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.

  题目就是求方案数,一看数据范围,差不多就是状态压缩啥的,然后DP就好。

  dp[i][j] 表示前i列,第i列的分布状态为j时的方案数。

代码如下:

// ━━━━━━神兽出没━━━━━━
// ┏┓ ┏┓
// ┏┛┻━━━━━━━┛┻┓
// ┃ ┃
// ┃ ━ ┃
// ████━████ ┃
// ┃ ┃
// ┃ ┻ ┃
// ┃ ┃
// ┗━┓ ┏━┛
// ┃ ┃
// ┃ ┃
// ┃ ┗━━━┓
// ┃ ┣┓
// ┃ ┏┛
// ┗┓┓┏━━━━━┳┓┏┛
// ┃┫┫ ┃┫┫
// ┗┻┛ ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━ // Author : WhyWhy
// Created Time : 2015年07月21日 星期二 09时43分34秒
// File Name : 3254.cpp #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> using namespace std; const int mod=; int N,M;
int map1[][];
int rem[];
long long dp[][]; int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); long long ans; while(~scanf("%d %d",&N,&M))
{
for(int i=;i<=N;++i)
for(int j=;j<=M;++j)
scanf("%d",&map1[i][j]); for(int i=;i<=M;++i)
{
rem[i]=; for(int j=;j<=N;++j)
if(!map1[j][i])
rem[i]|=(<<(j-));
} memset(dp,,sizeof(dp)); for(int j=;j<(<<N);++j)
if(!(j&rem[] || j&(j<<)))
++dp[][j]; for(int i=;i<=M;++i)
for(int j=;j<(<<N);++j)
{
if(j&(j<<) || j&rem[i])
continue; for(int k=;k<(<<N);++k)
{
if(j&k)
continue; (dp[i][j]+=dp[i-][k])%=mod;
}
} ans=; for(int j=;j<(<<N);++j)
(ans+=dp[M][j])%=mod; printf("%lld\n",ans);
} return ;
}

(简单) POJ 3254 Corn Fields,状压DP。的更多相关文章

  1. POJ 3254 - Corn Fields - [状压DP水题]

    题目链接:http://poj.org/problem?id=3254 Time Limit: 2000MS Memory Limit: 65536K Description Farmer John ...

  2. POJ 3254 Corn Fields (状压dp)

    题目链接:http://poj.org/problem?id=3254 给你n*m的菜地,其中1是可以种菜的,而菜与菜之间不能相邻.问有多少种情况. 状压dp入门题,将可以种菜的状态用一个数的二进制表 ...

  3. [ An Ac a Day ^_^ ] POJ 3254 Corn Fields 状压dp

    题意: 有一块n*m的土地 0代表不肥沃不可以放牛 1代表肥沃可以放牛 且相邻的草地不能同时放牛 问最多有多少种放牛的方法并对1e8取模 思路: 典型的状压dp 能状态压缩 能状态转移 能状态压缩的题 ...

  4. Poj - 3254 Corn Fields (状压DP)(入门)

    题目链接:https://vjudge.net/contest/224636#problem/G 转载于:https://blog.csdn.net/harrypoirot/article/detai ...

  5. poj 3254 Corn Fields 状压dp入门

    题目链接 题意 在\(M\times N\)的\(0,1\)格子上放东西,只有标记为\(1\)的格子可以放东西,且相邻的格子不能同时放东西.问有多少种放法. 思路 参考:swallowblank. \ ...

  6. POJ 1684 Corn Fields(状压dp)

    描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ ...

  7. POJ 3254 Corn Fields (状压入门)

    Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M≤ 12; 1 ≤ N ≤ 12) ...

  8. 【POJ3254】Corn Fields 状压DP第一次

    !!!!!!! 第一次学状压DP,其实就是运用位运算来实现一些比较,挺神奇的.. 为什么要发“!!!”因为!x&y和!(x&y)..感受一下.. #include <iostre ...

  9. P1879 [USACO06NOV]玉米田Corn Fields 状压dp/插头dp

    正解:状压dp/插头dp 解题报告: 链接! ……我真的太菜了……我以为一个小时前要搞完的题目调错误调了一个小时……90分到100我差不多搞了一个小时…… 然后这题还是做过的……就很气,觉得确实是要搞 ...

  10. [USACO06NOV]玉米田Corn Fields 状压DP

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

随机推荐

  1. WPF(ContentControl和ItemsControl)

    WPF(ContentControl和ItemsControl) 2013-04-01 16:25 2188人阅读 评论(0) 收藏 举报  分类: .Net(C#)(31)  WPF(25)  版权 ...

  2. TextureView+SurfaceTexture+OpenGL ES来播放视频(一)

    引自:http://www.ithao123.cn/content-8733143.html 最近发现视频直播类应用层出不穷,比如233手游直播,蓝鲸直播,微录客等等什么的,连android界大神老罗 ...

  3. Android OpenGL ES .介绍

    引自:http://blog.csdn.net/hgl868/article/details/6971624 1.    OpenGL ES 简介 Android 3D引擎采用的是OpenGL ES. ...

  4. 如何给grldr.mbr和grldr改名

    grldr修改方法: 比如要把grldr 改成gzldr :1.先把文件名改成gzldr:2.用ultraedit或winhex打开gzldr:3.虽然文本框全都是乱码,别管它,把光标定位在右边文本框 ...

  5. 11--tag 和transform属性

    tag 和transform属性 1.tag 标签,就相当于身份识别的标码,可以通过tag值获取对应的对象. 2.使用transform 实现对象的平移和旋转. // // ViewControlle ...

  6. 平移关节(Prismatic Joint)

    package{ import Box2D.Common.Math.b2Vec2; import Box2D.Dynamics.b2Body; import Box2D.Dynamics.Joints ...

  7. sites

    search http://213.240.44.13/ http://1.179.252.95/

  8. 别说你不知道java中的包装类,wrapper type,以及容易在自动拆箱中出现的问题

    很多时候,会有人问你,你知道什么是包装类吗? 或者高端一点问你你知道,wrapper type,是什么吗? 然后你就懵逼了,学了java很多时候都不知道这是啥. 其实问你的人,可能只是想问你,java ...

  9. java导出和读取excel数据

    使用的是poi的jar包 下载地址http://poi.apache.org/download.html 主要是把jar包导入,直接新建一个列子测试一下就明白了.使用起来还是比较方便的,代码里面的原理 ...

  10. 关于127.0.0.1与localhost

    127.0.0.1是不会经过防火墙的,而localhost是要通过防火墙取地址的.