【玉米田】

题目

代码

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;
            }
        }
    }
相关推荐
GalaxyPokemon1 小时前
归并排序:分治思想的高效排序
数据结构·算法·排序算法
ThreeYear_s1 小时前
基于FPGA的PID算法学习———实现PI比例控制算法
学习·算法·fpga开发
Coding小公仔3 小时前
LeetCode 240 搜索二维矩阵 II
算法·leetcode·矩阵
C++chaofan4 小时前
74. 搜索二维矩阵
java·算法·leetcode·矩阵
Studying 开龙wu4 小时前
机器学习监督学习实战五:六种算法对声呐回波信号进行分类
学习·算法·机器学习
Mi Manchi265 小时前
力扣热题100之二叉树的层序遍历
python·算法·leetcode
wu~9705 小时前
leetcode:42. 接雨水(秒变简单题)
算法·leetcode·职场和发展
zhurui_xiaozhuzaizai6 小时前
模型训练-关于token【低概率token, 高熵token】
人工智能·算法·自然语言处理
ThreeYear_s6 小时前
基于FPGA的PID算法学习———实现PID比例控制算法
学习·算法·fpga开发