【玉米田】

题目

代码

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;
            }
        }
    }
相关推荐
不会代码的小猴16 小时前
7. JSON
开发语言·c++·笔记·qt·算法·json
怪奇云呼军17 小时前
知识库也会注入指令?闪电智能VoiceAgent 如何防住 Prompt Injection
人工智能·python·算法·云计算·音视频
阿里云大数据AI技术17 小时前
基于 EMR Serverless Ray 实现 Qwen 模型批量推理实践
人工智能·算法·agent
Rambo.xia18 小时前
为什么去马赛克算法,决定了ISP的画质上限
算法·接口隔离原则
Benny_Tang18 小时前
题解:P10230 [COCI 2023/2024 #4] Lepeze
c++·算法
Geek-Chow18 小时前
06 训练管线:数据如何变成权重
人工智能·算法
我变成萤火虫19 小时前
反悔贪心(经典题目讲解)
c++·算法·贪心算法·stl·排序算法·反悔贪心
nike0good19 小时前
April Fools Day Contest 2026 题解
算法·题解·愚人节比赛
_Narcissus_19 小时前
排序算法总结表格
c语言·数据结构·c++·笔记·算法·排序算法·总结