HDU 2089 Digital DP Getting Started

Source: Internet
Author: User

Start learning Digital DP ... A problem that saw the code thought yesterday played nearly two hours today. Finally, I saw someone else's code to find a bug ... (lost)

The legend of the Academy is to be canceled? ... It's not a shame to go out with this dish.

#include <stdio.h> #include <string.h> #include <algorithm> #include <map> #include <math.h > #include <queue>using namespace std;int n,m;///digital DP with 62 and 4 unlucky///DP array used to save the first I-bit with J-start of the auspicious number int dp[11][11];void init () {memset (Dp,0,sizeof (DP)); for (int. i=0;i<=9;i++) dp[1][i]=1;dp[1][4]=0;for (int i=2;i<=7;i++) {for (int j=0;j< =9;j++) {for (int k=0;k<=9;k++) {if (j!=4&&! (        j==6&&k==2)) Dp[i][j]+=dp[i-1][k];    }}}}int cal (int x) {if (x==0) return 1;int a[11];int z=0;while (x>0) {z++;    a[z]=x%10; x/=10;} int ans=0; a[z+1]=0;for (int i=z;i>=1;i--) {for (int j=0;j<a[i];j++) {if (j!=4&&! (    a[i+1]==6&&j==2)) Ans+=dp[i][j]; } if ((a[i+1]==6&&a[i]==2) | | | a[i]==4) break;} return ans;}    int main () {init (); while (~SCANF ("%d%d", &n,&m)) {if (n==0&&m==0) break; printf ("%d\n", Cal (m+1)-cal (n));}}

  

HDU 2089 Digital DP entry

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.