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<<T) [1] + = dp[i][j][k][0]; ElseDp[i+1][t][k| (1<<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<<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)