Using a pressure DP to calculate the number of unlocking schemes for nine Gongge on a mobile phone

Source: Internet
Author: User

First there are two restrictions:

1. At least four points.

2. From one point to another point, if they are connected through another point, if this point has not passed, then must pass, otherwise you can skip the middle point.

If you are unfamiliar with the restrictions, you can try it yourself.

The number of States is rarely only 2^9, so directly with the pressure DP get up ~ ~

Dp[i][state] represents the number of scenarios in which the state is last stopped on node I, where state is a binary number, 1 indicates that the point of the position has passed, and 0 indicates that it has not passed, then the equation for the transition is:

Dp[j][state| ( 1<<J)]+=dp[i][state] indicates state from I to j~~~.

The enumeration of the process of attention to various restrictions on the good ~ ~ ~

Directly on the code:

intcheck[9][9];intdp[Ten][ -];intMain () {memset (check,0,sizeof(check)); Memset (DP,0,sizeof(DP)); check[0][8]=check[8][0]=4; check[0][2]=check[2][0]=1; check[3][5]=check[5][3]=4; check[6][8]=check[8][6]=7; check[2][6]=check[6][2]=4; check[0][6]=check[6][0]=3; check[1][7]=check[7][1]=4; check[2][8]=check[8][2]=5;  for(intI=0;i<9; ++i) dp[i][(1<<i)]=1;  for(intI=1;i< (1<<9);++i) for(intj=0;j<9;++j)if(i& (1<<j)) for(intk=0;k<9;++k)if(! (i& (1<<k )))if(!check[j][k]| | (i& (1<<Check[j][k]))) Dp[k][i| (1&LT;&LT;K)]+=Dp[j][i]; intans=0;  for(intI=0;i<9;++i) for(intj=1;j< (1<<9);++j) {intK=j,cnt=0;  while(k) {++CNT; K=k& (K-1); }            if(cnt>3) ans+=Dp[i][j]; } printf ("%d\n", ans); return 0;}

Using a pressure DP to calculate the number of unlocking schemes for nine Gongge on a mobile phone

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.