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;
}

时间: 2024-08-28 10:53:16

Orz_panda cup I题 (xdoj1117) 状压dp的相关文章

[luoguP3694] 邦邦的大合唱站队/签到题(状压DP)

传送门 来自kkk的题解: 70分做法:枚举每个学校顺序,暴力. 100分:状压dp.从队列头到尾DP, 状态:f[i]表示i状态下最小的出列(不一致)的个数. 比如f[1101]表示从头到位为1/3/4乐队的偶像的最小出列个数. f[i]=min(f[i\ xor\ 2^j]+num[j]-(sum[length][j]-sum[length-num[j]][j]));f[i]=min(f[i xor 2?j??]+num[j]−(sum[length][j]−sum[length−num[j

【专业找水题】状压dp最水题,没有之一

题目链接 现在代码能力没上升,倒是越来越会找水题了(比例题还水的裸题你值得拥有) 这网站不是针对竞赛的,所以时空限制都很宽松 然后就让我水过去了 对于每个点,包括自己的前m个元素是否取都是一种状态,所以状压一下(才1024不要怂) 1 #include <cstdio> 2 int n,m,q; 3 int a[1001]; 4 int dp[1001][2000]; 5 int max(int a,int b){return(a<b)?b:a;} 6 int main() 7 { 8

2014牡丹江网络预选赛D题(状压DP)zoj3812

We Need Medicine Time Limit: 10 Seconds      Memory Limit: 65536 KB      Special Judge A terrible disease broke out! The disease was caused by a new type of virus, which will lead to lethal lymphoedema symptom. For convenience, it was named LL virus.

nefu1109 游戏争霸赛(状压dp)

题目链接:http://acm.nefu.edu.cn/JudgeOnline/problemShow.php?problem_id=1109 //我们校赛的一个题,状压dp,还在的人用1表示,被淘汰的人用0表示.倒着循环即可. //比赛的时候我用的是二维dp数组表示状态,一直是WA的,搞不懂原因...Orz... 代码: #include<iostream> #include<cstdio> #include<algorithm> #include<cstrin

POJ 2411 &amp;&amp; HDU 1400 Mondriaan&#39;s Dream (状压dp 经典题)

Mondriaan's Dream Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 12341   Accepted: 7204 Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series

刷题总结——bzoj1725(状压dp)

题目: 题目描述 Farmer John 新买了一块长方形的牧场,这块牧场被划分成 N 行 M 列(1<=M<=12; 1<=N<=12),每一格都是一块正方形的土地. FJ 打算在牧场上的某几格土地里种上美味的草,供他的奶牛们享用.遗憾的是,有些土地相当的贫瘠,不能用来放牧.并且,奶牛们喜欢独占一块草地的感觉,于是 FJ 不会选择两块相邻的土地,也就是说,没有哪两块草地有公共边.当然,FJ 还没有决定在哪些土地上种草. 作为一个好奇的农场主,FJ 想知道,如果不考虑草地的总块数,

刷题向》关于第一篇状压DP BZOJ1087 (EASY+)

这是本蒟蒻做的第一篇状压DP,有纪念意义. 这道题题目对状压DP十分友善,算是一道模板题. 分析题目,我们发现可以用0和1代表每一个格子的国王情况, 题目所说国王不能相邻放置,那么首先对于每一行是否合法的判断条件就出来了:就是对于情况X,如果X&(x<<1)==0,即为合法情况. 同理这样我们就可以得出每一行对于上一行是否合法的条件:(x&y)==0&&(x&(y<<1))==0&&(x&(y>>1))==

P3694 邦邦的大合唱站队/签到题(状压dp)

P3694 邦邦的大合唱站队/签到题 题目背景 BanG Dream!里的所有偶像乐队要一起大合唱,不过在排队上出了一些问题. 题目描述 N个偶像排成一列,他们来自M个不同的乐队.每个团队至少有一个偶像. 现在要求重新安排队列,使来自同一乐队的偶像连续的站在一起.重新安排的办法是,让若干偶像出列(剩下的偶像不动),然后让出列的偶像一个个归队到原来的空位,归队的位置任意. 请问最少让多少偶像出列? 输入输出格式 输入格式: 第一行2个整数N,M. 接下来N个行,每行一个整数a_i(1\le a_i

QDUOJ 来自xjy的签到题(bfs+状压dp)

来自xjy的签到题 Description 爱丽丝冒险来到了红皇后一个n*n大小的花园,每个格子由'.'或'#'表示,'.'表示爱丽丝可以到达这个格子,‘#’表示爱丽丝不能到达这个格子,爱丽丝每1分钟可以移动到非'#'的相邻格子(与当前所在格子具有公共边).花园下面有m个隧道,每个隧道有一个出口和一个入口.当爱丽丝到达隧道的入口时,她可以选择(也可以不选择)进入隧道入口,并通过隧道一次,然后立即(不花费时间)出现在隧道出口.爱丽丝一开始可以降临在花园的任何地方.有好奇心的爱丽丝想知道,她通过所有