poj 3254 Corn Field 状态压缩dp

农夫约翰新购得一块牧场,需要规划如何种植玉米供奶牛食用。考虑到奶牛不喜欢相邻吃草,约翰需要计算在限制条件下有多少种种植方案。此问题可通过动态规划解决。

Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yummy corn for the cows on a number of squares. Regrettably, some of the squares are infertile and can’t be planted. Canny FJ knows that the cows dislike eating close to each other, so when choosing which squares to plant, he avoids choosing squares that are adjacent; no two chosen squares share an edge. He has not yet made the final choice as to which squares to plant.

Being a very open-minded man, Farmer John wants to consider all possible options for how to choose the squares for planting. He is so open-minded that he considers choosing no squares as a valid option! Please help Farmer John determine the number of ways he can choose the squares to plant.

Input
Line 1: Two space-separated integers: M and N
Lines 2.. M+1: Line i+1 describes row i of the pasture with N space-separated integers indicating whether a square is fertile (1 for fertile, 0 for infertile)
Output
Line 1: One integer: the number of ways that FJ can choose the squares modulo 100,000,000.
Sample Input
2 3
1 1 1
0 1 0
Sample Output
9
Hint
Number the squares as follows:
1 2 3
4

There are four ways to plant only on one squares (1, 2, 3, or 4), three ways to plant on two squares (13, 14, or 34), 1 way to plant on three squares (134), and one way to plant on no squares. 4+3+1+1=9.

题目大意: 农夫有一块地,被划分为m行n列大小相等的格子,其中一些格子是可以放牧的(用1标记),农夫可以在这些格子里放牛,其他格子则不能放牛(用0标记),并且要求不可以使相邻格子都有牛。现在输入数据给出这块地的大小及可否放牧的情况,求该农夫有多少种放牧方案可以选择(注意:任何格子都不放也是一种选择,不要忘记考虑!

考虑总数的话 就是每个状态叠加 考虑状态最大值就是求最大的状态。
这个叠加状态即可

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int mod=1e8;
int dp[30][1010];
int mp[30];
int st[1010];
int n,m;
int ok(int x)
{
    if((x<<1)&x) return 0;
    return 1;
}
int tot;
void findst()
{
    int en=(1<<m);
    for(int i=0;i<en;i++)
    {
        if(ok(i)) st[tot++]=i;
    }
}

int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        memset(dp,0,sizeof(dp));
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                int a;
                scanf("%d",&a);
                if(a==0)
                mp[i]|=(1<<j);
            }
        }
        tot=0;
        findst();
        for(int i=0;i<tot;i++)
        {
            if(st[i]&mp[0]) continue;
            dp[0][i]=1;
        }
        for(int r=1;r<n;r++)
        {
            for(int i=0;i<tot;i++)
            {
                if(st[i]&mp[r]) continue;
                for(int j=0;j<tot;j++)
                {
                    if(st[i]&st[j]) continue;
                    if(st[j]&mp[r-1]) continue;
                    dp[r-1][j]%=mod;
                    dp[r][i]+=dp[r-1][j];
                    dp[r][i]%=mod;
                }
            }
        }
        int maxx=0;
        for(int i=0;i<tot;i++)
        {
            maxx=(maxx+dp[n-1][i])%mod;
        }
        printf("%d\n",maxx );
    }
}
参照刘海建(2023)的做法,本团队对来自经济管理《供应链数字化与企业绩效—机制与经验证据》一文中的基准回归部分进行复刻 根据《关于开展供应链创新与应用试点的通知》的名单,团队整理了上市公司-供应链数字化示范名单DID(数据详见前文)。其他控制变量主要来自上市公司年报 一、数据介绍 数据名称:供应链数字化与企业绩效—机制与经验证据 数据范围:上市公司 数据年份:2013-2022年 有效样本:23276条 数据来源:《关于开展供应链创新与应用试点的通知》、上市公司年报 内含原始数据、dofile和基准回归 二、数据指标 企业绩效A 净利润/ 净资产 企业绩效B 托宾Q值 试点企业 《关于开展供应链创新与应用试点的通知》中的266家企业与上市公司匹配。其中上市公司-供应链数字化示范名单DID(数据详见前文) DID Tread*Time:供应链创新与应用试点企业在2018年之后赋值为1,否则为0 资产规模 总资产的自然对数 资产负债率 总负债/总资产 营业收入增长率 (当年营业收入-上年营业收入)/上年营业收入 固定资产比例 固定资产/总资产 董事会规模 董事会人数总和 独董比例 独立董事人数/董事会人数总和 成立年限 (当年年份-成立年份)的对数 三、参考文献 刘海建等.供应链数字化与企业绩效——机制与经验证据[J].经济管理,2023,45(05):78-98. 供应链数字化通过提升企业管理效率,激发企业成长潜力,提高企业经营绩效 供应链数字化有助于提高企业的创新能力,提高企业经营绩效
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值