当前位置:网站首页>【AcWing 327. 玉米田】状压dp
【AcWing 327. 玉米田】状压dp
2022-07-28 02:19:00 【宇智波一打七~】
题目链接
题意:
农夫约翰的土地由 M×N 个小方格组成,现在他要在土地里种植玉米。
非常遗憾,部分土地是不育的,无法种植。
而且,相邻的土地不能同时种植玉米,也就是说种植玉米的所有方格之间都不会有公共边缘。
现在给定土地的大小,请你求出共有多少种种植方法。
土地上什么都不种也算一种方法。
输入格式
第 1 行包含两个整数 M 和 N。
第 2…M+1 行:每行包含 N 个整数 0 或 1,用来描述整个土地的状况,1 表示该块土地肥沃,0 表示该块土地不育。
输出格式
输出总种植方法对 108 取模后的值。
分析:
枚举每行的可以种植的状态,这个状态就是和题目中给出的状态取个或就行,然后对每种状态判断一下是否合法然后再枚举转移的状态就可以,下面看代码:
#include<bits/stdc++.h>
using namespace std;
const int N = 13,mod = 1e8;
typedef long long LL;
LL f[N][1<<N];
int g[N];
vector<int> hefa;
int main(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
int x;
for(int j=1;j<=m;j++){
cin>>x;
g[i] = g[i]*2 + x;
}
}
for(int i=0;i<(1<<m);i++){
if((i&(i>>1))==0) hefa.push_back(i);
}
f[0][0] = 1;
LL ans = 0;
for(int i=1;i<=n;i++){
for(auto j : hefa){
if((g[i]|j) == g[i]){
for(auto x : hefa){
if((j&x)==0)
f[i][j] = (f[i][j]+f[i-1][x])%mod;
}
}
if(i == n) ans = (ans + f[i][j]) % mod;
}
}
cout<<ans<<endl;
return 0;
}
边栏推荐
- 没法预测明天的涨跌
- Docker高级篇-Docker容器内Redis集群配置
- style=“width: ___“ VS width=“___“
- [elm classification] classification of UCI data sets based on nuclear limit learning machine and limit learning machine, with matlab code
- ORACLE BASICFILE LOB字段空间回收SHRINK SPACE的疑惑
- Pytest the best testing framework
- 智能工业设计软件公司天洑C轮数亿元融资
- Where do I go to open an account for stock speculation? Is it safe to open an account on my mobile phone
- 分布式事务——Senta(一)
- JS 事件对象 offsetX/Y clientX Y PageX Y
猜你喜欢

微服务架构统一安全认证设计与实践

为什么登录时,明明使用的是数据库里已经有的账号信息,但依旧显示“用户不存在”?

Day 8 of DL

别再用 offset 和 limit 分页了,性能太差!
![Trivy [1] tool scanning application](/img/b1/c05949f9379fcde658da64f3a0157a.png)
Trivy [1] tool scanning application

ECCV 2022 | open source for generative knowledge distillation of classification, detection and segmentation

【stream】并行流与顺序流

机器人工程是否有红利期

Opengauss Developer Day 2022 sincerely invites you to visit the "database kernel SQL Engine sub forum" of Yunhe enmo

On the problem that sqli labs single quotation marks do not report errors
随机推荐
Where do I go to open an account for stock speculation? Is it safe to open an account on my mobile phone
[signal denoising] signal denoising based on Kalman filter with matlab code
[signal processing] weak signal detection in communication system based on the characteristics of high-order statistics with matlab code
Confusion matrix in CNN | pytorch series (XXIII)
MySQL index learning
超参数调整和实验-训练深度神经网络 | PyTorch系列(二十六)
[ACNOI2022]总差一步
What "posture" does JD cloud have to promote industrial digitalization to climb to a "new level"?
Redis aof日志持久化
别再用 offset 和 limit 分页了,性能太差!
GBase8s如何在有外键关系的表中删除数据
Skills in writing English IEEE papers
@Valid的作用(级联校验)以及常用约束注解的解释说明
【微信小程序开发(六)】绘制音乐播放器环形进度条
QT专题1:实现一个简易计算器
没法预测明天的涨跌
Which of the four solutions of distributed session do you think is the best?
微服务架构统一安全认证设计与实践
OA项目之我的审批(会议查询&会议签字)
“29岁,普通功能测试,我是如何在一周内拿到5份Offer的?”