HDU 4734 F (x) (digital DP)

Source: Internet
Author: User

F (x)

Time limit:1000/500 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2190 Accepted Submission (s): 828


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 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 INPUT30 1001 105 100

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

Source2013 ACM/ICPC Asia Regional Chengdu Online

Recommendliuyiding

1#include <cstdio>2#include <algorithm>3#include <iostream>4#include <cmath>5#include <cstring>6 #definell Long Long7 8 using namespacestd;9 Ten intN; One intp[ A]; A intb; - intFA,FB; - intnum[ A]; the intdp[ A][25010]; -  - voidinit () { -p[0]=1; +      for(intI=1; i<=Ten; i++) -p[i]=p[i-1]*2; + } A  at intDfsintIintSBOOLe) { -     if(i==-1)returns>=0; -     if(s<0)return 0; -     if(!e&&dp[i][s]!=-1)returnDp[i][s]; -     intU=e?num[i]:9; -     intres=0; in      for(intD=0; d<=u; d++) { -         intnews=s-d*P[i]; toRes+=dfs (I-1, news,e&&d==u); +     } -     returne?res:dp[i][s]=Res; the } *  $ intSolveintx) {Panax Notoginseng     intlen=0; -      while(x) { thenum[len++]=x%Ten; +X/=Ten; A     } the     returnDFS (len-1, FA,1); + } -  $ intMain () { $     //freopen ("In.txt", "R", stdin); -memset (dp,-1,sizeofDP); - init (); the     intT; -     intCa=1;WuyiCin>>T; the      while(t--) { -scanf"%d%d",&a,&b); Wu         intk=0; -Has0; About          while(a) { $fa+=p[k]* (a%Ten); -A/=Ten, k++; -         } -         //cout<< "fa=" <<fa<<endl; Aprintf"Case #%d:%d\n", ca++, solve (b)); +     } the     return 0; -}

HDU 4734 F (x) (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.