[USACO06NOV] Corn Fields
https://www.luogu.org/problem/show?pid=1879
题目描述
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
- 状压DP
- #include<cstdio>
- #define mod 1000000000
- using namespace std;
- int n,m;
- int poor[],separate[],cnt,dp[][];
- bool not_adjoin_lr(int i)
- {
- if(i&i<<) return false;
- return true;
- }
- bool not_adjoin_ud(int i,int j)
- {
- if(i&j) return false;
- return true;
- }
- bool can(int i,int h)
- {
- if(i&poor[h]) return false;
- return true;
- }
- int main()
- {
- int x;
- scanf("%d%d",&n,&m);
- for(int i=;i<n;i++)
- for(int j=;j<m;j++)
- {
- scanf("%d",&x);
- if(!x) poor[i+]+=<<j;
- }
- int tot=<<m;
- for(int i=;i<tot;i++)
- if(not_adjoin_lr(i))
- separate[++cnt]=i;
- for(int i=;i<=cnt;i++)
- if(can(separate[i],)) dp[][i]=;
- for(int i=;i<=n;i++)
- {
- for(int j=;j<=cnt;j++)
- {
- if(!can(separate[j],i-)) continue;
- for(int k=;k<=cnt;k++)
- {
- if(!can(separate[k],i)) continue;
- if(!not_adjoin_ud(separate[j],separate[k])) continue;
- dp[i][k]=(dp[i][k]+dp[i-][j])%mod;
- }
- }
- }
- int ans=;
- for(int i=;i<=cnt;i++) ans=(ans+dp[n][i])%mod;
- printf("%d",ans);
- }
[USACO06NOV] Corn Fields的更多相关文章
- 状压 DP:[USACO06NOV] Corn Fields,[USACO13NOV] No Change
[USACO06NOV] Corn Fields (试题来源:Link ) 题目描述 Farmer John has purchased a lush new rectangular pasture ...
- 【题解】洛谷P1879 [USACO06NOV] Corn Fields(状压DP)
洛谷P1879:https://www.luogu.org/problemnew/show/P1879 思路 把题目翻译成人话 在n*m的棋盘 每个格子不是0就是1 1表示可以种 0表示不能种 相邻的 ...
- P1879 [USACO06NOV] Corn Fields G
题目描述 农场主John新买了一块长方形的新牧场,这块牧场被划分成M行N列(1 ≤ M ≤ 12; 1 ≤ N ≤ 12),每一格都是一块正方形的土地.John打算在牧场上的某几格里种上美味的草,供他 ...
- P1879 [USACO06NOV]玉米田Corn Fields(状压dp)
P1879 [USACO06NOV]玉米田Corn Fields 状压dp水题 看到$n,m<=12$,肯定是状压鸭 先筛去所有不合法状态,蓝后用可行的状态跑一次dp就ok了 #include& ...
- 状压DP【洛谷P1879】 [USACO06NOV]玉米田Corn Fields
P1879 [USACO06NOV]玉米田Corn Fields 农场主John新买了一块长方形的新牧场,这块牧场被划分成M行N列(1 ≤ M ≤ 12; 1 ≤ N ≤ 12),每一格都是一块正方形 ...
- 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 \ ...
- USACO Corn Fields
洛谷 P1879 [USACO06NOV]玉米田Corn Fields 洛谷传送门 题目描述 Farmer John has purchased a lush new rectangular past ...
随机推荐
- NTP错误总结
Ntp错误总结 解决ntp的错误 no server suitable for synchronization found 当用ntpdate -d 来查询时会发现导致 no server suita ...
- “Hello World”团队第一周博客汇总
时间:2017-10-13——2017-10-19 Scrum会议: 会议要求博客:https://edu.cnblogs.com/campus/nenu/SWE2017FALL/homework/1 ...
- “Hello World!”团队第三周召开的第五次会议
一.会议时间 二.会议地点 三.会议成员 四.会议内容 五.todo list 六.会议照片 七.燃尽图 八.代码地址 一.会议时间 2017年10月31日 11:45-12:17 二.会议地点: ...
- sql 至少含有
查询Score表中至少有5名学生选修的并以3开头的课程的平均分数: select avg(degree),cnofrom scorewhere cno like '3%'group by cnohav ...
- 深入理解Java之数据类型
一.概述 我们通过编程解决一个具体问题时,首先要做的工作是用各种“数据结构”表示问题中的实体对象,而后才能着手研究描述具体业务逻辑的算法.这也正印证了”程序 = 数据结构 + 算法“.而这里的数据结构 ...
- ACM 第十五天
计算几何基础 练习题 C - Wasted Time Mr. Scrooge, a very busy man, decided to count the time he wastes on all ...
- node中的__dirname
先说结论:__dirname指的是当前文件所在文件夹的绝对路径. 测试路径如下: 即 根目录/dir0.js 根目录/path1/dir1.js 根目录/paht1/path2/dir2.js 每个d ...
- ubuntu 安装xdebug
Add XDebug to Ubuntu 14.04 Submitted by Wilbur on Tue, 06/17/2014 - 12:49pm It's pretty easy to add ...
- js 控制
js 制动控制 代码 是 :setInterval(function(){$(".egg").click();},1000); 使用方法:调出浏览器放控制台(console),一般 ...
- Pandas速查手册中文版(转)
关键缩写和包导入 在这个速查手册中,我们使用如下缩写: df:任意的Pandas DataFrame对象 同时我们需要做如下的引入: import pandas as pd 导入数据 pd.read_ ...