poj 3254

来源:互联网 发布:链轮设计参数计算软件 编辑:程序博客网 时间:2024/06/07 01:15
<span style="font-size:18px;">//题目网址 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=121145#problem/G</span>
<span style="font-size:18px;"></span>
<span style="font-size:18px;">#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn=4096,inf=1000000000;int matrix[15][15],r,c,table[maxn],k=0,dp[15][maxn+1];void gettable(){    int i;    for(i=0;i<(1<<c);++i)    {        if((i&(i<<1))==0) table[k++]=i;//按位运算还是加括号不然会错    }}bool is_ok(int x,int r){    int i,tmp=0;    for(i=0;i<c;i++)    {        if(matrix[r][i]) tmp+=(1<<(c-i-1));    }    if(x&(~tmp))return false;//按位与写成&&了。。改了好久    return true;}int main(){    int i,j,rr,res=0;    scanf("%d%d",&r,&c);    for(i=0;i<r;i++)        for(j=0;j<c;j++)            scanf("%d",&matrix[i][j]);    gettable();    memset(dp,0,sizeof(dp));    for(i=0;i<k;i++)//初始化    {        if(is_ok(table[i],0)) dp[0][table[i]]=1;    }    for(rr=0;rr<r-1;rr++)    {        for(i=0;i<k;i++)        {            if(is_ok(table[i],rr))            {                for(j=0;j<k;j++)                {                    if(is_ok(table[j],rr+1) && !(table[i]&table[j]))                    {                        dp[rr+1][table[j]]+=dp[rr][table[i]];                    }                }            }        }    }    for(i=0;i<k;i++)    {        res=(res+dp[r-1][table[i]])%inf;    }    printf("%d\n",res);    return 0;}</span>

0 0
原创粉丝点击