HDU-4734-F (x)

Source: Internet
Author: User

Problem DescriptionFor a decimal number x with n digits (AnAn-1An-2... a2A1), we define its weight as F (x) = An * 2n-1 + An-1*2n-2 +... + A2 * 2 + A1 * 1. now you are given two numbers A and B, please calculate how many numbers are there between 0 and B, aggressive, whose weight is no more than F ().
InputThe first line has a number T (T <= 10000), indicating the number of test cases.
For each test case, there are two numbers A and B (0 <= A, B <109)
OutputFor every case, you shoshould output "Case # t:" at first, without quotes.TIs the case number starting from 1. Then output the answer.
Sample Input

30 1001 105 100

Sample Output
Case #1: 1Case #2: 2Case #3: 13

Source2013 ACM/ICPC Asia Regional Chengdu Online
A simple digital DP !!!! DP [pos] [sum] records the number of records whose length is pos less than or equal to sum, so that no Initialization is required each time. At the beginning, DP records whose length is pos, the first len-pos number and sum number, because the DP value in each group is not necessarily the same, for example, 1 10 dp [0] [0] = 1; 2 100 dp [0] [0] = 2; therefore, Initialization is required every time, which is also the cause of timeout. This is a good DP question!
#include 
 
  #include 
  
   #include 
   
    #include 
    
     #include 
     
      #include #include 
      
       using namespace std;int dp[12][4600];int A,B;int F;vector 
       
         digit;void init(){ F = 0; int t = 0; while(A){ F += (A%10)*(1<
        
          F) break; res += dfs(pos-1,val + i*(1<
         
          > ncase; memset(dp,-1,sizeof dp); while(ncase--){ cin >> A >> B; init(); printf("Case #%d: %d\n",T++,solve(B)); } 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.