Hdu 2089 must be 62-digit dp

Source: Internet
Author: User

Hdu 2089 must be 62-digit dp

# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       # Include
        
          # Include
         
           # Include
          
            Using namespace std; int dp [10] [3]; // dp [I] [j] indicates the number of digits, j indicates the status. // dp [I] [0] indicates that an unlucky number does not exist. // dp [I] [1] indicates that the Geely number does not exist, and the highest bit is 2 // dp [I] [2], indicating that there is an unlucky number void init () {memset (dp, 0, sizeof (dp )); dp [0] [0] = 1; // initialize the unlucky number of 0 digits as 1for (int I = 1; I <= 7; I ++) {dp [I] [0] = dp [I-1] [0] * 9-dp [I-1] [1]; // The highest digit does not contain 9 digits of 4, and because when the I-th digit is set to 6, i-1 can not put 2 SO to subtract the I-1 bit does not exist unlucky number to cut the highest bit of 2 dp [I] [1] = dp [I-1] [0]; // The highest bit puts 2 other digits as long as it is not unlucky numbers can dp [I] [2] = dp [I-1] [2] * 10 + dp [I-1] [0] + dp [I-1] [1]; // The number of I-BITs containing unlucky digits is the number of I-1-BITs containing unlucky digits × 10, as long as there is an unlucky number in the back, no matter what the front can be, so the first X 10, and if the highest bit put a 4, then all the following are not unlucky numbers, you can also put the highest bit on a 6 and then put the second to the last bit on 2. It's not unlucky.} int fun (int n) {int len = 0, tem = n, ans, flag, a [10]; while (n) {a [++ len] = n % 10; n/= 10 ;} a [len + 1] = ans = 0; flag = 0; // obtain the unlucky number between 1-(n-1) for (int I = len; i> = 1; I --) {ans + = dp [I-1] [2] * a [I]; // The following I-1 is an unlucky number and then the front can be filled with any if (flag) {ans + = dp [I-1] [0] * a [I];} if (! Flag & a [I]> 4) {ans + = dp [I-1] [0]; // if a [I]> 4, you can put a 4} if (! Flag & a [I + 1] = 6 & a [I]> 2) {// if the last digit is 6, ans + = dp [I] [1];} if (! Flag & a [I]> 6) {ans + = dp [I-1] [1];} if (a [I] = 4 | a [I + 1] = 6 & a [I] = 2) {flag = 1 ;}} return tem-ans;} int main () {int n, m; init (); while (cin> n> m, n | m) {printf ("% d \ n", fun (m + 1)-fun (n);} return 0 ;}
          
         
        
      
     
    
   
  
 

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.