HDU 4734 F (x)

Source: Internet
Author: User

F (x) Time limit:500msmemory limit:32768kbthis problem'll be is judged onHDU. Original id:4734
64-bit integer IO format: %i64d Java class name: Main For 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 is given numbers A and B, please calculate how many numbers is there between 0 and B, inclusive, whose weigh T is no more than F (A).InputThe first line has a number T (T <= 10000), indicating the number of test cases.
For each test case, there is numbers A and B (0 <= B < 109)OutputFor every case,you should output ' case #t: ' At first, without quotes. The 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
SourceACM/ICPC Asia Regional Chengdu Online Problem solving: Digital DP
1#include <bits/stdc++.h>2 using namespacestd;3 intdp[Ten][200010],pos[Ten];4 intFintx) {5     intb =1, ret =0;6      while(x) {7RET + = XTen*b;8X/=Ten;9b <<=1;Ten     } One     returnret; A } - intDfsintLenintNowBOOLflag) { -     if(Len <0)returnNow >=0; the     if(Now <0)return 0; -     if(!flag && Dp[len][now]! =-1)returnDp[len][now]; -     intD = Flag?pos[len]:9, ret =0; -      for(inti =0; I <= D; ++i) +RET + = DFS (len-1, now-i* (1<<len), flag&&i==d); -     if(!flag) Dp[len][now] =ret; +     returnret; A } at intCalcintAintb) { -     intCNT =0; -      while(b) { -pos[cnt++] = b%Ten; -b/=Ten; -     } in     returnDFS (cnt-1, F (a),true); - } to intMain () { +     intkase,a,b; -scanf"%d",&Kase); thememset (dp,-1,sizeofDP); *      for(intCS =1; CS <= Kase; ++CS) { $scanf"%d%d",&a,&b);Panax Notoginsengprintf"Case #%d:%d\n", Cs,calc (A, b)); -     } the     return 0; +}
View Code

HDU 4734 F (x)

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.