Hud2089_ Digital DP

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=2089

Reprinted from http://blog.csdn.net/acm_cxlove/article/details/7819907

N-m's tree does not contain 4 and 62 of the number of how many

1#include <iostream>2#include <cstring>3#include <queue>4#include <cstdio>5#include <cmath>6#include <algorithm>7 #defineN 558 #defineINF 1<<299 #defineMOD 9973Ten #defineLL Long Long One #defineEPS 1e-7 A #defineZero (a) fabs (a) <eps - #defineEqual (A, B) zero (a) - using namespacestd; the intdp[Ten][3]; - //Dp[i][0], indicating that there is no unlucky number - //Dp[i][1], indicating that no unlucky number is present, and that the highest position is 2 - //Dp[i][2], indicating the presence of an unlucky number + voidInit () { -Memset (DP,0,sizeof(DP)); +dp[0][0]=1; A      for(intI=1; i<=6; i++){ atdp[i][0]=dp[i-1][0]*9-dp[i-1][1];//at the highest bit plus 9 numbers other than 4, but may have added 6 before 2. -dp[i][1]=dp[i-1][0];//is to add 2 to the top of the original non-unlucky number. -dp[i][2]=dp[i-1][2]*Ten+dp[i-1][0]+dp[i-1][1];//Add an arbitrary number to the highest number of unlucky digits, or add 4 before the number is not auspicious, or add 4 to the front of the 2. -     } - } - intSlove (intN) { in     intlen=0, bit[Ten]; -     inttmp=N; to      while(n) { +bit[++len]=n%Ten; -N/=Ten; the     } *bit[len+1]=0; $     intans=0;Panax Notoginseng     BOOLflag=false; -      for(inti=len;i;i--){ theans+=dp[i-1][2]*Bit[i];  +         if(flag)//the high has already appeared 4 or 62, and the back is random. Aans+=dp[i-1][0]*Bit[i]; the         if(!flag&&bit[i]>4)//a high position can occur in 4 +ans+=dp[i-1][0]; -         if(!flag&&bit[i+1]==6&&bit[i]>2)//The High is 6, the back one may appear 2, this step has been debug for a long time $ans+=dp[i][1]; $         if(!flag&&bit[i]>6)//The high may appear 6, to the back of the highest bit of 2 count into -ans+=dp[i-1][1]; -         if(bit[i]==4|| (bit[i+1]==6&&bit[i]==2))//The high has already appeared in 4 or theflag=true; -     }Wuyi     returntmp-ans; the } - intMain () { Wu     intL,r; - Init (); About      while(SCANF ("%d%d", &l,&r)!=eof&&l+R) $printf"%d\n", Slove (r+1)-Slove (L)); -     return 0; -}
View Code

Hud2089_ Digital DP

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.