[USACO06NOV] Corn Fields G
[USACO06NOV] Corn Fields G
状压 板子题, 也是我的第一道状压 .
设 为第 行状态为 时的方案数, 则上下两行没有相邻的用 来判, 同一行没有相邻的用 来判.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int read() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
const int mod = 1e8;
int n, m, f[15][1 << 12], s[15];
int main() {
n = read(), m = read();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
s[i] = (s[i] << 1) + read();
}
}
f[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < (1 << m); j++) {
for (int k = 0; k < (1 << m); k++) {
if (!(k & j) && (s[i] & k) == k && !(k << 1 & k) && !(k >> 1 & k)) {
f[i][k] += f[i - 1][j];
if (f[i][k] >= mod) f[i][k] -= mod;
}
}
}
}
int ans = 0;
for (int i = 0; i < (1 << m); i++) {
ans += f[n][i];
if (ans >= mod) ans -= mod;
}
printf("%d", ans);
return 0;
}
看不见我看不见我看不见我
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】凌霞软件回馈社区,携手博客园推出1Panel与Halo联合会员
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 长文讲解 MCP 和案例实战
· Hangfire Redis 实现秒级定时任务,使用 CQRS 实现动态执行代码
· Android编译时动态插入代码原理与实践
· 解锁.NET 9性能优化黑科技:从内存管理到Web性能的最全指南
· 通过一个DEMO理解MCP(模型上下文协议)的生命周期
· 工良出品 | 长文讲解 MCP 和案例实战
· 多年后再做Web开发,AI帮大忙
· 记一次 .NET某旅行社酒店管理系统 卡死分析
· centos停服,迁移centos7.3系统到新搭建的openEuler
· 一天 Star 破万的开源项目「GitHub 热点速览」
2019-09-06 放苹果