【luogu P1879 [USACO06NOV]玉米田Corn Fields】 题解
题目链接:https://www.luogu.org/problemnew/show/P1879
状压DP。
设dp[i][j]表示第i行,状态为j的方案数
初始dp[0][0] = 1
这样一共12行12列,最多1<<12。
这样转移时,只要满足上下没有两个1,这两行分别满足没有相邻1。
加法原理转移。
\(j&k==0\)
$ dp[i][j] += dp[i-1][k] $
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn = 5000;
const int mod = 100000000;
ll a[20][maxn], dp[20][maxn], n, m, b[20], ans, is[maxn];
int main()
{
cin>>n>>m;
for(ll i = 1; i <= n; i++)
for(ll j = 1; j <= m; j++) cin>>a[i][j];
for(ll i = 1; i <= n; i++)
for(ll j = 1; j <= m; j++)
if(a[i][j]) b[i] += (1<<(m-j+1));
for(ll i = 1; i <= n; i++) b[i] >>= 1;
for(ll i = 0; i < (1 << m); i++)
if((i&(i<<1)) == 0 && (i&(i>>1)) == 0) is[i] = 1;
dp[0][0] = 1;
for(ll i = 1; i <= n; i++)
{
for(ll j = 0; j < (1 << m); j++)
{
if(is[j] && ((j & b[i]) == j))
for(ll k = 0; k < (1 << m); k++)
{
if((j & k) == 0)
dp[i][j] = (dp[i][j] + dp[i-1][k])%mod;
}
}
}
for(ll i = 0; i < (1 << m); i++) ans = (ans + dp[n][i]) % mod;
cout<<ans%mod;
}
【luogu P1879 [USACO06NOV]玉米田Corn Fields】 题解的更多相关文章
- 洛谷 P1879 [USACO06NOV]玉米田Corn Fields 题解
P1879 [USACO06NOV]玉米田Corn Fields 题目描述 Farmer John has purchased a lush new rectangular pasture compo ...
- luogu P1879 [USACO06NOV]玉米田Corn Fields
题目描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ...
- C++ 洛谷 P1879 [USACO06NOV]玉米田Corn Fields
没学状压DP的看一下 合法布阵问题 P1879 [USACO06NOV]玉米田Corn Fields 题意:给出一个n行m列的草地(n,m<=12),1表示肥沃,0表示贫瘠,现在要把一些牛放在 ...
- P1879 [USACO06NOV]玉米田Corn Fields(状压dp)
P1879 [USACO06NOV]玉米田Corn Fields 状压dp水题 看到$n,m<=12$,肯定是状压鸭 先筛去所有不合法状态,蓝后用可行的状态跑一次dp就ok了 #include& ...
- 洛谷P1879 [USACO06NOV]玉米田Corn Fields(状压dp)
洛谷P1879 [USACO06NOV]玉米田Corn Fields \(f[i][j]\) 表示前 \(i\) 行且第 \(i\) 行状态为 \(j\) 的方案总数.\(j\) 的大小为 \(0 \ ...
- 洛谷P1879 [USACO06NOV]玉米田Corn Fields【状压DP】题解+AC代码
题目描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ...
- P1879 [USACO06NOV]玉米田Corn Fields (状压dp入门)
题目链接: https://www.luogu.org/problemnew/show/P1879 具体思路: 我们可以先把所有合法的情况枚举出来,然后对第一行判断有多少种情况满足,然后对于剩下的行数 ...
- 洛谷 P1879 [USACO06NOV]玉米田Corn Fields
题目描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ...
- 洛谷P1879 [USACO06NOV]玉米田Corn Fields (状态压缩DP)
题目描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ...
随机推荐
- MVC 中使用kindEditor 图片上传在IE 上进行上传出现的问题
在IE 上使用KindEditor 进行单张图片上传的时候会出现一个下载安全警告,这样将会造成图片上传失败,出现的错误页面:
- sql中,In和where的区别
SQL 语句中In 和 Where 的含义不同.应用解释如下: 1.如需有条件地从表中选取.删除.更新数据时,使用Where:2.In只作为Where条件子句下的一个运算符,除了In之外还有Betwe ...
- Oracle数据库RowId
RowId是什么? RowId是根据每一行数据的物理信息地址编码而成的一个位列,利用RowId可以快速定位到某一行. Oracle数据库编辑数据必须查出RowId,可以根据如下语句查询: select ...
- C# 读取excel用户列表过滤一个月内未收到外部邮件已离职的员工
1.通过aspose.cells读取excel中的数据并添加到list中 //存储从excel中读取出来的数据 List<UserInfo> lst_userinfo = new List ...
- IoT Gateway Based on OSGi
1. OSGi Knowleage 2. OSGi.Net on Windows 3. OSGi with JAVA 4. OSGi with Qt and C++ 5. Architecture o ...
- Python爬虫框架Scrapy教程(1)—入门
最近实验室的项目中有一个需求是这样的,需要爬取若干个(数目不小)网站发布的文章元数据(标题.时间.正文等).问题是这些网站都很老旧和小众,当然也不可能遵守 Microdata 这类标准.这时候所有网页 ...
- Keras 自适应Learning Rate (LearningRateScheduler)
When training deep neural networks, it is often useful to reduce learning rate as the training progr ...
- No value specified for 'Date'错误
今天使用 BeanUtils.copyProperties(m,n); 遇到 No value specified for 'Date' 这个错误,以前用的时候都不需要加 try 今天使用发现需 ...
- C#多个线程同时执行一个任务示例
注意:如果电脑是单核单线程的,这么做是没有意义的. 这里直接贴一下主要代码 using System; using System.Collections.Generic; using System.T ...
- [翻译] LazyFadeInView 渐入显示text文本
LazyFadeInView 渐入显示text文本 https://github.com/itouch2/LazyFadeInView LazyFadeInView is a cool way to ...