B. Filling the Grid codeforces

Posted lllaih

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了B. Filling the Grid codeforces相关的知识,希望对你有一定的参考价值。

题目链接:https://codeforces.com/contest/1228/problem/B

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
#define mem(a,b) memset(a,b,sizeof(a))

using namespace std;
string a[1005];
const int mod = 1e9+7;
int dir[4][2] = 0,1,0,-1,1,0,-1,0;
 int main()

    int h,w,r[1005],c[1005],ans[1005][1005];
    while(cin >> h >> w) 
        int flag = 0;
        memset(ans,0,sizeof(ans));
        for(int i = 1; i <= h;i++) 
            cin >> r[i];
        
        for(int i = 1; i <= w; i++) 
            cin >> c[i];
        
        //1 代表空 2 代表满
        for(int i = 1; i <= h; i++) 
            if(r[i] == 0) 
                ans[i][1] = 1;
                continue;
            
            for(int j = 1; j <= r[i];j++) 
                ans[i][j] = 2;
            
            if(r[i] < w)//让最后一个满的下一个为空
                ans[i][r[i]+1] = 1;
        
        for(int i = 1; i <= w; i++) 
            if(c[i] == 0)
                if(ans[1][i] == 2) 
                    flag = 1;
                    break;
                
                ans[1][i] = 1;
                continue;
            
            for(int j = 1; j <= c[i]; j++) 
                if(ans[j][i] == 1) 
                    flag = 1;
                    break;
                
                ans[j][i] = 2;
            
            if(flag == 1)
                break;
            if(c[i] < h)
            
                if(ans[c[i]+1][i] == 2)
                
                    flag = 1;
                    break;
                
                ans[c[i]+1][i] = 1;
            
        
        int sum = 0;
        for(int i = 1; i <= h; i++) 
            for(int j = 1; j <= w; j++) 
                if(ans[i][j] == 0)
                    sum++;
            
        
        int anss = 0;
        for(int i = 0; i <= sum; i++)
            if(i == 0)
                anss = 1;
            else 
                anss*=2;
                anss %= mod;
            
        if(flag == 1) anss = 0; //如果不满足条件break掉的 答案为0
        cout << anss << endl;
    
    return 0;

 

以上是关于B. Filling the Grid codeforces的主要内容,如果未能解决你的问题,请参考以下文章

Another Filling the Grid

CF1228E Another Filling the Grid

CF1228E Another Filling the Grid

E. Another Filling the Grid 状压dp

Codeforces 1228E. Another Filling the Grid

[Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理)