比赛 2024暑假C班集训A 评测结果 AAAAAAAAAA
题目名称 牧场的安排 最终得分 100
用户昵称 liuyiche 运行时间 0.037 s
代码语言 C++ 内存使用 3.41 MiB
提交时间 2024-07-10 10:57:23
显示代码纯文本
#include <bits/stdc++.h>
            
using namespace std;

typedef long long ll;

int mod = 100000000;
int n, m;
ll ans = 0;
bool e[15][15];
ll f[15][4100];
bool flag[4100];
//bool pp[15][4100];

inline void get_s(int step, int z)
{
    if(step == m+1)
    {
        flag[z] = 1;
        //cout << z << " ";
        return;
    }
    if(z%2 == 0)
        get_s(step+1,(z<<1)+1);
    get_s(step+1,z<<1);
}

inline bool pd(int z, int id)
{
    //cout << z << " ";
    for(int i = m; i > 0; --i)
    {
        if(e[id][i] == 0 && z%2 == 1)
            return false;
        z /= 2;
    }
    return true;
}
    
int main()
{
    freopen("cowfood.in", "r", stdin);
    freopen("cowfood.out", "w", stdout);
        
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
            
    cin >> n >> m;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
            cin >> e[i][j];
    get_s(1,0);
    for(int i = 0; i < 1<<m; ++i)
        if(pd(i,1) == true)
        {
            f[1][i] = flag[i];
        }
    //for(int i = 0; i < 1<<m; ++i)
    //    cout << f[1][i]<< " ";
    for(int i = 2; i <= n; ++i)
    {
        for(int j = 0; j < 1<<m; ++j)
        {
            if(flag[j] == 0)
                continue;
            for(int k = 0; k < 1<<m; ++k)
            {
                if(flag[k] == 0 || pd(k,i) == false)
                    continue;
                bool tmp = true;
                int a = j, b = k;
                for(int z = 1; z <= m; ++z)
                {
                    if(a%2 == 1 && b%2 == 1)
                    {
                        tmp = false;
                        //cout << "!";
                        break;
                    }
                    a /= 2, b /= 2;
                }
                if(tmp == true)
                {
                    f[i][k] += f[i-1][j];
                    f[i][k] %= mod;
                }
                //cout << i << " " << j << " " << k << " " << f[i][k] << '\n';
            }
        }
    }
    
    for(int i = 0; i < 1<<m; ++i)
        ans += f[n][i], ans %= mod;
    //for(int i = 0; i < 1<<m; ++i)
    //    cout << f[n][i] << " ";
    cout << ans;
    
   	return 0;
}