?
?
to calculate the number of balanced numbers in a given range [x, y].
Input The input contains multiple test cases. The first line is the total number of cases T (0 < T ≤ 30). For each case, there are two integers separated by a space in a line, x and y. (0 ≤ x ≤ y ≤ 10 18).
Output For each case, print the number of balanced numbers in the range [x, y] in a line.
Sample Input
2 0 9 7604 24324
Sample Output
10 897
/** hdu 3709 数位dp(小思维) 解题思路:有一个很好的转化技巧,不然会超时。搜索的时候初始值定为f(x),然后最后和0比较。不要搜f(i) 和f(x)比较 */ #include#include #include #include using namespace std; typedef long long LL ; LL dp[25][25][2000],l,r; int bit[25]; LL dfs(int len,int pos,int sum,int flag) { if(len<0) { //printf(%d %d>>>> ,suml,sumr); return sum==0; } if(flag==0&&dp[len][pos][sum]!=-1) return dp[len][pos][sum]; int end=flag?bit[len]:9; LL ans=0; for(int i=0;i<=end;i++) { //printf(len-1:%d ,len-1); ans+=dfs(len-1,pos,(sum+(len-pos)*i),flag&&i==end); } if(flag==0) { dp[len][pos][sum]=ans; } return ans; } LL solve(LL n) { if(n==-1)return 0; int len=0; while(n) { bit[len++]=n%10; n/=10; } LL ans=0; for(int i=0;i ?