【玉米田】

题目

代码

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const int mod = 1e8;
const int M = 1 << 12;
LL f[13][M];
int g[13];
vector<int> state;
vector<int> p[M];
int n, m;
bool check(int x)
{
    return !(x & x << 1);
}
int main()
{
    cin >> m >> n;
    for(int i = 1; i <= m; i++)
    {
        for(int j = 0; j < n; j++)
        {
            int t;
            cin >> t;
            g[i] |= !t << j;
        }
    }
    
    for(int i = 0; i < 1 << n; i++)
    {
        if(check(i)) state.push_back(i);
    }
    
    for(auto a : state)
        for(auto b : state)
        {
            if((a & b) == 0) p[a].push_back(b);
        }
    
    f[0][0] = 1;
    for(int i = 1; i <= m+1; i++)
    {
        for(auto a : state)
        {
            f[i&1][a] = 0;
            if(a & g[i]) continue;
            for(auto b : p[a])
            {
                f[i&1][a] = (f[i&1][a] + f[(i-1)&1][b]) % mod;
            }
        }
    }
    
    cout << f[(m+1)&1][0];
    return 0;
}

注意

采用滚动数组时,一定要注意恢复,而且不仅是更新之前恢复,对于那些不更新的值也要恢复,因为不更新不代表继承上一次的值,而是采用默认值,因此必须恢复,下面的这个代码就闹了这个笑话

cpp 复制代码
    f[0][0] = 1;
    for(int i = 1; i <= m+1; i++)
    {
        for(auto a : state)
        {
            f[i&1][a] = 0;
            if(a & g[i]) continue;
            //f[i&1][a] = 0;
            for(auto b : p[a])
            {
                f[i&1][a] = (f[i&1][a] + f[(i-1)&1][b]) % mod;
            }
        }
    }
相关推荐
hans汉斯23 分钟前
【计算机科学与应用】基于BERT与DeepSeek大模型的智能舆论监控系统设计
大数据·人工智能·深度学习·算法·自然语言处理·bert·去噪
多喝开水少熬夜1 小时前
损失函数系列:focal-Dice-vgg
图像处理·python·算法·大模型·llm
立志成为大牛的小牛2 小时前
数据结构——三十七、关键路径(王道408)
数据结构·笔记·程序人生·考研·算法
ytttr8732 小时前
基于MATLAB的Relief算法特征权重选择实现
算法
Freshman小白3 小时前
python算法打包为docker镜像(边缘端api服务)
python·算法·docker
mit6.8243 小时前
[VT-Refine] Simulation | Fine-Tuning | docker/run.sh
算法
朴shu3 小时前
Delta数据结构:深入剖析高效数据同步的奥秘
javascript·算法·架构
mit6.8244 小时前
博弈dp|凸包|math分类
算法
Shinom1ya_4 小时前
算法 day 41
数据结构·算法·leetcode
hetao17338375 小时前
2025-10-30 ZYZOJ Star(斯达)模拟赛 hetao1733837的record
c++·算法