Orz_panda cup I題 (xdoj1117) 狀壓dp

來源:互聯網
上載者:User

標籤:

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 1112 311110
範例輸出
14
很簡單的狀壓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

 

Orz_panda cup I題 (xdoj1117) 狀壓dp

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.