One of the key counts-HDU 1438 (State compression table)

Source: Internet
Author: User

Analysis: The first thought of the end of each key has 4 states, but the topic also needs to be judged there are three different key depths, so each depth after the end of the 2^4 species, 0000->1111, but the topic needs to have adjacent key depth of more than or equal to 3, So two different states are required to indicate that 0 means that there is no such thing, 1 indicates that it has occurred, and then a 4-dimensional array is opened for state transfer. Dp[maxn][bit][1<<bit][2].

The code is as follows:

=============================================================================================================== =============

#include <stdio.h>#include<string.h>#include<algorithm>#include<math.h>using namespacestd;Const intMAXN = +;Const intbit =4;Long Longdp[maxn][bit][1<<bit][2];intMain () {dp[1][0][1][0] = dp[1][1][2][0] =1; dp[1][2][4][0] = dp[1][3][8][0] =1;  for(intI=1; i<maxn; i++)     for(intj=0; j<bit; J + +)     for(intk=0; k< (1<<bit); k++)    {        if(dp[i][j][k][0])        {             for(intt=0; t<4; t++)            {                if(ABS (j-t) = =3) Dp[i+1][t][k| (1&LT;&LT;T) [1] + = dp[i][j][k][0]; ElseDp[i+1][t][k| (1&LT;&LT;T) [0] + = dp[i][j][k][0]; }        }        if(dp[i][j][k][1])        {             for(intt=0; t<4; t++) Dp[i+1][t][k| (1&LT;&LT;T) [1] + = dp[i][j][k][1]; }    }    Long Longsum[maxn]={0};  for(intI=3; i<maxn; i++)     for(intj=0; j<bit; J + +)     for(intk=7; k< -; k++)    {        if(k==7|| k== One|| k>= -) Sum[i]+ = dp[i][j][k][1]; }     for(intI=2; i<maxn; i++) {printf ("n=%d:%lld\n", I, sum[i]); }    return 0;}

One of the key counts-HDU 1438 (State compression table)

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.