Bzoj 1087 pressure DP

Source: Internet
Author: User

Pre-process the line-type pressure values of each row into Mark, and record the sum of points contained in this value

Whether the pressure values of each adjacent two rows can be stored in dis


DP equation: DP [I] [l] [K + sum [l] + = DP [I-1] [J] [k]; the L status of row I has K + sum [l] + = number of solutions for K in the J status of the previous row.


#include "stdio.h"#include "string.h"int b[21];int n,m,i,j,l,k,cnt;long long ans,dp[2][101][90];int dis[101][101],sum[101],mark[101];int get(int x){    int sum;    sum=0;    while (x!=0)    {        sum+=x%2;        x/=2;    }    return sum;}int judge1(int x){    if (x&(x<<1)) return 0;    if (x&(x>>1)) return 0;    return 1;}int judge2(int x,int y){    if (x&y) return 0;    if (x&(y<<1)) return 0;    if (x&(y>>1)) return 0;    return 1;}int main(){    b[0]=1;    for (i=1;i<=10;i++)        b[i]=b[i-1]*2;    while (scanf("%d%d",&n,&m)!=EOF)    {        cnt=0;        for (i=0;i<b[n];i++)            if (judge1(i)==1)            {                cnt++;                mark[cnt]=i;                sum[cnt]=get(i);            }        memset(dis,0,sizeof(dis));        for (i=1;i<=cnt;i++)            for (j=1;j<=cnt;j++)            if (judge2(mark[i],mark[j])==1)            dis[i][j]=1;        memset(dp,0,sizeof(dp));        dp[0][1][0]=1;        for (i=1;i<=n;i++)        {            memset(dp[i%2],0,sizeof(dp[i%2]));            for (j=1;j<=cnt;j++)                for (k=0;k<=m;k++)                if (dp[1-i%2][j][k])                    for (l=1;l<=cnt;l++)                        if (dis[j][l]&&k+sum[l]<=m)                            dp[i%2][l][k+sum[l]]+=dp[1-i%2][j][k];        }        ans=0;        for (i=1;i<=cnt;i++)            ans+=dp[n%2][i][m];        printf("%lld\n",ans);    }    return 0;}



Bzoj 1087 pressure DP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.