"Hdoj" one of the 1438 key counts

Source: Internet
Author: User

State compression. The value of the last slot and whether the current configuration scheme can be DP.

1 /*1438*/2#include <cstdio>3#include <cstring>4#include <cstdlib>5 6 #defineMAXN 327 8 Const intMaxs =1<<4;9 Ten__int64 dp[maxn][maxs][4][2]; One intcnt[1<<4]; A  - intAbsintx) { -     returnx<0? -x:x; the } -  - intMain () { -     intI, J, K, N; +     ints; - __int64 ans; +      Amemset (CNT,0,sizeof(CNT)); at      for(i=0; i<maxs; ++i) -          for(j=0; j<4; ++j) -             if(I & (1<<j)) -++Cnt[i]; -      -Memset (DP,0,sizeof(DP)); in      for(i=0; i<4; ++i) -dp[1][1<<i][i][0] =1; to          +      for(n=2; n<maxn; ++N) { -          for(i=0; i<maxs; ++i) { the              for(j=0; j<4; ++j) { *                  for(k=0; k<4; ++k) { $s = i | (1<<j);Panax Notoginsengdp[n][s][j][1] + = dp[n-1][i][k][1]; -                     if(ABS (j-k) = =3) { thedp[n][s][j][1] + = dp[n-1][i][k][0]; +}Else { Adp[n][s][j][0] + = dp[n-1][i][k][0]; the                     } +                 } -             } $         } $     } -      -      for(n=2; n<maxn; ++N) { theAns =0; -          for(i=0; i<maxs; ++i) {Wuyi             if(Cnt[i] >=3) theAns + = dp[n][i][0][1] + dp[n][i][1][1] + -dp[n][i][2][1] + dp[n][i][3][1]; Wu         } -printf"n=%d:%i64d\n", n, ans); About     } $      -     return 0; -}

"Hdoj" one of the 1438 key counts

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.