F(x)

Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 382    Accepted Submission(s): 137

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
 
Recommend
liuyiding
 

数位DP的水题

dp[i][j]表示i位值<=j 的总数

/* ***********************************************
Author :kuangbin
Created Time :2013/9/14 星期六 12:45:42
File Name :2013成都网络赛\1007.cpp
************************************************ */ #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std; int dp[][]; int bit[]; int dfs(int pos,int num,bool flag)
{
if(pos == -)return num >= ;
if(num < )return ;
if(!flag && dp[pos][num] != -)
return dp[pos][num];
int ans = ;
int end = flag?bit[pos]:;
for(int i = ;i <= end;i++)
{ ans += dfs(pos-,num - i*(<<pos),flag && i==end);
}
if(!flag)dp[pos][num] = ans;
return ans;
} int F(int x)
{
int ret = ;
int len = ;
while(x)
{
ret += (x%)*(<<len);
len++;
x /= ;
}
return ret;
}
int A,B;
int calc()
{
int len = ;
while(B)
{
bit[len++] = B%;
B/=;
//cout<<bit[len-1]<<endl;
}
//cout<<F(A)<<endl;
return dfs(len-,F(A),);
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
int iCase = ;
scanf("%d",&T);
memset(dp,-,sizeof(dp));
while(T--)
{
iCase++;
scanf("%d%d",&A,&B);
printf("Case #%d: %d\n",iCase,calc());
}
return ;
}

HDU 4734 F(x) (2013成都网络赛,数位DP)的更多相关文章

  1. HDU 4733 G(x) (2013成都网络赛,递推)

    G(x) Time Limit: 2000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  2. HDU 4737 A Bit Fun (2013成都网络赛)

    A Bit Fun Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  3. HDU 4731 Minimum palindrome (2013成都网络赛,找规律构造)

    Minimum palindrome Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  4. HDU 4730 We Love MOE Girls (2013成都网络赛,签到水题)

    We Love MOE Girls Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. HDU 4768 Flyer (2013长春网络赛1010题,二分)

    Flyer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  6. HDU 4747 Mex (2013杭州网络赛1010题,线段树)

    Mex Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submis ...

  7. HDU 4734 F(x) 2013 ACM/ICPC 成都网络赛

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4734 数位DP. 用dp[i][j][k] 表示第i位用j时f(x)=k的时候的个数,然后需要预处理下小 ...

  8. HDU 4737 A Bit Fun 2013成都 网络赛 1010

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4737 题目大意:给定一系列数,F(i,j)表示对从ai到aj连续求或运算,(i<=j)求F(i, ...

  9. 2013成都网络赛 J A Bit Fun(水题)

    A Bit Fun Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. 第11月第31天 keyboardwillshow CGAffineTransformMakeTranslation

    1. - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)registerN ...

  2. NOI2001 方程的解数(双向搜索)

    solution 一道非常经典的双向搜索题目,先将前3个未知数枚举一遍得到方程的前半部分所有可能的值,取负存入第一个队列中再将后3个未知数枚举一遍,存入第二个队列中.这样我们只要匹配两个队列中相同的元 ...

  3. 【Pyhon】利用BurpSuite到SQLMap批量测试SQL注入

    前言 通过Python脚本把Burp的HTTP请求提取出来交给SQLMap批量测试,提升找大门户网站SQL注入点的效率. 导出Burp的请求包 配置到Burp的代理后浏览门户站点,Burp会将URL纪 ...

  4. RESTful 个人理解总结【转】

    转自:http://www.cnblogs.com/wang-yaz/p/9237981.html 一.什么是RESTful 面向资源 简单的说:RESTful是一种架构的规范与约束.原则,符合这种规 ...

  5. 使用Python编写简单的端口扫描器的实例分享【转】

    转自 使用Python编写简单的端口扫描器的实例分享_python_脚本之家 http://www.jb51.net/article/76630.htm -*- coding:utf8 -*- #!/ ...

  6. 011_自定义mac通知的时长

    打开终端(找不到的点击 Mac 屏幕右上角放大镜按钮,Spotlight 搜索 “终端”),粘入下面这行命令,回车就行了.注意最后的 # 替换成你希望通知中心横幅停留的秒数,比如 15.default ...

  7. [Android]Eclipse 安装 ADT[Android Development Tooling] 失败的两种解决办法

    原因 最近想在新装的 Win7 里搭建一下 Android 的开发环境,虽然现在有 Android Studio 了,不过还是习惯 Eclipse 一点.众所周知的原因,Eclipse 直接安装 AD ...

  8. python 双层函数调用顺序

    读大神代码,见到大神封装的接口很多都是采用双层函数形式. def 外层函数(外层参数) def 内层函数(内层参数) 函数体 return 值 return 内层函数 类似这样的形式,使用 外层函数( ...

  9. 【linux】环境变量

    参考链接: http://www.cnblogs.com/growup/archive/2011/07/02/2096142.html https://zhidao.baidu.com/questio ...

  10. redis配置文件redis.conf翻译、解释以及常用注意事项(持续更新中...)

    # Redis configuration file example. #Redis 配置文件的示例 #如何利用配置文件启动Redis # Note that in order to read the ...