题目描述

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的余数。

简单的状压。

#include<iostream>
#include<cstdio>
using namespace std;
const int mod=100000000;
int n,m,tot,ans,mp[15],f[15][5005],a[5005];
void dfs(int num,int lst,int res)
{if(num==m){a[++tot]=res;return ;}dfs(num+1,lst,res);if(num-lst>=2)dfs(num+1,num,res|(1<<num));
}
int main()
{scanf("%d%d",&n,&m);for(int i=1;i<=n;i++)for(int j=0;j<=m-1;j++){int x;scanf("%d",&x);mp[i]|=((x^1)<<j);}dfs(0,-2,0);f[0][1]=1;for(int i=1;i<=n;i++)//行数 for(int j=1;j<=tot;j++)//上一行的状态 if(f[i-1][j]>0)for(int k=1;k<=tot;k++)if(!(a[k]&a[j])&&!(a[k]&mp[i]))f[i][k]=(f[i][k]+f[i-1][j])%mod;for(int i=1;i<=tot;i++)ans=(ans+f[n][i])%mod;printf("%d\n",ans);return 0;
}

洛谷 P1879 [USACO06NOV]玉米田Corn Fields相关推荐

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

    P1879 [USACO06NOV]玉米田Corn Fields 时间限制 1.00s 内存限制 125.00MB 题目描述 Farmer John has purchased a lush new ...

  2. 洛谷P1879 [USACO06NOV]玉米田Corn Fields

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

  3. [USACO06NOV]玉米田Corn Fields题解

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

  4. [USACO06NOV]玉米田Corn Fields(动态规划,状态压缩)

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

  5. [USACO06NOV]玉米田Corn Fields

    题目 https://www.luogu.org/problemnew/show/P1879 思路 用状态表示草地最外层,转移时按状态判断 代码 #include<cstdio> usin ...

  6. [USACO06NOV]玉米田Corn Fields (状压$dp$)

    题目链接 Solution 状压 \(dp\) . \(f[i][j][k]\) 代表前 \(i\) 列中 , 已经安置 \(j\) 块草皮,且最后一位状态为 \(k\) . 同时多记录一个每一列中的 ...

  7. 洛谷 P1825 [USACO11OPEN]玉米田迷宫Corn Maze

    题目描述 去年秋天,奶牛们去参观了一个玉米迷宫,迷宫里有一些传送装置,可以将奶牛从一点到另一点进行瞬间转移.这些装置可以双向使用:一头奶牛可以从这个装置的起点立即到此装置的终点,同时也可以从终点出发, ...

  8. 刷题周记(九)——#状压DP:最短Hamilton路径、小国王(互不侵犯)、玉米田(Corn Fields G)、愤怒的小鸟、吃奶酪、炮兵阵地、宝藏 #区间DP:清空字符串#DP:关灯问题II

    文章目录 --2020年12月20日(周日)------------------ 状压DP 一.最短Hamilton路径(模板题) 二.玉米田(P1879 [USACO06NOV]Corn Field ...

  9. jzoj1266,P1879-[USACO06NOV]玉米田Corn Fields【状态压缩,dp】

    正题 评测记录:https://www.luogu.org/recordnew/lists?uid=52918&pid=P1879 大意 有n*m的矩阵,有些地方可以放,有些不可以放,不可以相 ...

最新文章

  1. centos mysql 连接数_CentOS7.2_调整mysql数据库最大连接数
  2. ARM 汇编学习——编写简单的ARM汇编程序
  3. ibator使用心得
  4. 用得最多的altium版本_83版《神雕》有多猛?收视率破90%!金庸最满意的版本...
  5. linux下的powerline安装教程
  6. 2018 Multi-University Training Contest 3: G. Interstellar Travel(凸包)
  7. java ajaxupload_Java中利用ajaxfileupload.js组件实现文件的上传功能
  8. spring_150904_hibernatetemplate
  9. Windows 10 Install SQL Server 2005
  10. powerapps简介
  11. FastReport.NET v2022.2.7
  12. 必看! 为什么“吉祥物”可以提高UI设计以及品牌影响力
  13. Web 面试之 HTTP和浏览器
  14. 教师资格证面试 计算机应用,请问下,中职类教师资格证,科目是计算机应用。可..._教师招聘考试_帮考网...
  15. 计算机学报杂志官网在线出版,计算机学报
  16. BUUCTF-Crypto【1-20T】
  17. Vue3 + Photo-sphere-viewer 全景
  18. c语言实现家谱(孩子兄弟树)数据结构
  19. 抖音创始人张一鸣:10年面试2000人,我发现混的好的人,全都有同一个特质
  20. Word问题解决-双栏论文左下角作者简介信息的编辑-脚注

热门文章

  1. 机械硬盘的工作原理详细解析,以及机械硬盘和固态硬盘的优缺点对比
  2. 轻松Git与Github入门
  3. 计算机网络知识点及例题总结(五)数据链路层与局域网
  4. iOS10访问通讯录、相册等隐私权限设置
  5. HDMI/DVI设备热插拨检测
  6. 车羊问题c语言编程,再谈“羊车门”问题
  7. 苹果手机直播显示服务器,搭建流媒体服务器(iOS直播 )
  8. 惠州市城市职业学院计算机考点,2020广东乡镇惠州考区笔试考点地理位置及考场安排表...
  9. 个人miniblog被迫备份至此
  10. 【免费】Linux命令行与Shell脚本编程大全 第3版 PDF全本 21MB 百度网盘下载