Orz_panda cup I题 (xdoj1117) 状压dp

Orz_panda cup I题 (xdoj1117)  状压dp

 

1117: Insert Orz Pandas

时间限制: 2 Sec  内存限制: 128 MB
提交: 15  解决: 5
[ 提交][ 状态][ 讨论版]

题目描述

Orz panda emotion is a famous emotion in XDU/ACM-ICPC QQ groups.
Big Big Xi loves to create new Orz panda emotions.
Now he has a matrix with n lines and m columns,form n*m cells.
And he wants to insert some small Orz pandas to this matrix to create a big emotion.
In each cell of the matrix,he will determine whether put a small Orz panda or not.
For some reasons,he has some special needs of the emotions:
1.In the ith column,there must be a[i] small Orz pandas. (1<=i<=m)
2.In the ith line,assume the total number of Orz pandas is x, x mod 2 must be b[i]. (1<=i<=n)
For example, if n=2 and m=3,a[1..3]={1,1,1},b[1..2]={1,0}

An adapted answer can be like this:

 

 

 

 

 

 

 

Now, Big Big Xi wants to know there are how many adapted ways to insert the pandas.

 

 

输入

There are multiple test cases (no more than 100,and no more than 10 test cases with large n and m), please process to EOF.

In each test case,there are two numbers N and M at the first line.(0<n<=10, 0<m<=100)

Then m lines, the ith line has a number indicates a[i].

And then n lines,the ith line has a number indicates b[i].

 

输出

One number which is the answer of the question (mod by 1e9+7)

 

样例输入

1 1
1
1
2 3
1
1
1
1
0

样例输出

1
4
很简单的状压dp,题目的数据范围也给了充分的提示,以及状态的处理也没什么麻烦的点,虽然比赛的时候没时间看。。。
#include<bits/stdc++.h>

using namespace std;

const int maxn=120;

typedef long long ll;
const ll MOD=1000000007;
int n,m;
int tS;
ll dp[maxn][1<<12];
int a,b;
vector<int> line[maxn];

int Cnt(int s)
{
    int res=0;
    for(int i=0;i<n;i++){
        if(s&(1<<i)) res++;
    }
    return res;
}

ll DP(int i,int j)
{
    ll &res=dp[i][j];
    if(~res) return res;
    if(i==0) return res=!j;
    res=0;
    for(int k=0;k<line[i].size();k++){
        res=(res%MOD+DP(i-1,j^line[i][k]))%MOD;
    }
    return res;
}

int main()
{
    while(cin>>n>>m){
        for(int i=1;i<=m;i++){
            line[i].clear();
            scanf("%d",&a);
            for(int j=0;j<(1<<n);j++){
                if(Cnt(j)==a) line[i].push_back(j);
            }
        }
        tS=0;
        for(int i=0;i<n;i++){
            scanf("%d",&b);
            tS|=(1<<i)*b;
        }
        memset(dp,-1,sizeof(dp));
        //cout<<DP(m,tS)<<'\n';
        printf("%lld\n",DP(m,tS));
    }
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/--560/p/4766382.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值