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;}