Problem Description
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 you are given two numbers A and B, please calculate how many numbers are there between 0 and B, inclusive, whose weight is no more than F(A).
 
Input
The 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)
 
Output
For every case,you should output "Case #t: " at first, without quotes. The t is the case number starting from 1. Then output the answer.
 
Sample Input
3
0 100
1 10
5 100
 
Sample Output
Case #1: 1
Case #2: 2
Case #3: 13
 
Source
#include <stdio.h>
#include <vector>
#include <string.h>
using namespace std;
vector <int> num;
int dp[][];
//dp状态设计成dp[pos][remain],remain表示还剩多少fA可以分配
int dfs(int pos, int remain, bool limit) //limit表示后面的数是否能乱填
{
if (pos == -) return remain >= ;
if (!limit && ~dp[pos][remain]) return dp[pos][remain];
int end = limit?num[pos]:;
int res = ;
for (int i = ; i <= end; i ++)
{
res += dfs(pos-, remain-(<<pos)*i, limit && (i == end));
}
if (!limit) dp[pos][remain] = res;
return res;
} int main()
{
int t;
scanf("%d", &t);
memset(dp, -,sizeof(dp));
for (int ca = ; ca <= t; ca ++)
{
int A, B;
scanf("%d %d", &A, &B);
num.clear();
while(B)
{
num.push_back(B % );
B /= ;
}
int fa = ;
for (int i = ; A; A /= , ++ i) fa += ( << i) * (A % );
printf("Case #%d: %d\n", ca, dfs(num.size()-, +fa, ));
}
return ;
}

数位DP模板(HDU 4734)

最新文章

  1. mm/makefile
  2. fastjson生成和解析json数据,序列化和反序列化数据
  3. Little Jumper---(三分)
  4. Flash Socket简单调试工具
  5. H.264中NAL、Slice与frame意思及相互关系
  6. 4种Java引用浅解
  7. elementui左侧菜单栏刷新后还是原来的状态
  8. Javascript继承3:将优点为我所有----组合式继承
  9. vue 打开新窗口
  10. Python 进程池的同步方法
  11. 第一篇,java学习之旅
  12. k8s之创建etcd集群
  13. gradle 汉化
  14. [Ubuntu] 如何设置静态 IP 和 DNS
  15. Linux root用户下强制静音的问题
  16. 20162311 Hash 补分博客
  17. Hive 基础你需要掌握这些
  18. C#文件与文件夹操作
  19. Hadoop(二)自定义输出
  20. zookeper集群

热门文章

  1. switch...case 和 if...else
  2. ecshop二次开发 给商品添加自定义字段
  3. (转载)c++builder/delphi中透明panel及透明窗口的实现方法_delphi教程
  4. 温故知新——json
  5. Python设计模式——装饰模式(Decorator)
  6. c++ union学习
  7. IOS 获得通讯录中联系人的所有属性 备用参考
  8. poj 3415 Common Substrings(后缀数组+单调栈)
  9. JNA—JNI终结者
  10. COOKIE之安全设置漫谈