1029 [USACO 2006 Oct S]Corn Fields 地图状压DP

 链接:https://ac.nowcoder.com/acm/contest/25022/1029
来源:牛客网

题目描述

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.

输入描述:

Line 1: two space-separated integers M and N
Lines 2.. M+1: row I +1 describes each cell in row I of the ranch, N space-separated integers indicating whether the cell can be planted (1 means fertile and suitable for planting, 0 means barren and not suitable for planting).

输出描述:

Line 1: an integer: FJ total number of alternatives divided by a remainder of 100,000,000.
示例1

输入

复制
2 3
1 1 1
0 1 0

输出

复制
9

分析

简单的地图状压DP

复制代码
//-------------------------代码----------------------------

#define int ll
const int N = 2e6+10,mod = 1e8;
int n,m;

V<int>num;
V<int>s;
int mp[15];
int dp[15][1 << 13];
void solve()
{
    cin>>n>>m;
    fo(i,1,n) {
        fo(j,1,m) {
            int x;cin>>x;
            if(!x)mp[i] |= 1 << (m - j);
        }
    }
    fo(i,0,(1<<m) - 1) {
        if(i >> 1 & i)continue;
        s.pb(i);
        bitset<64>bt(i);
        num.pb(bt.count());
    }
    dp[0][0] = 1;
    fo(i,1,n+1) {
        fo(j,0,s.size() - 1) {
            int p = s[j];
            if(p & mp[i]) continue;
            fo(k,0,s.size() - 1) {
                int q = s[k];
                if(p & q || q & mp[i-1]) continue;
                dp[i][j] = (dp[i][j] + dp[i-1][k] + mod) % mod;;
            }
        }
    }
    cout<<dp[n+1][0]<<endl;
}

signed main(){
    clapping();TLE;

//    int t;cin>>t;while(t -- )
    solve();
//    {solve(); }
    return 0;
}

/*样例区


*/

//------------------------------------------------------------
复制代码

 

posted @   er007  阅读(26)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示