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. Flex 经验笔记二

    向 Module 传递数据:好像只能传递些像 整型,字符型等简单类型的数据,也能传递像 json 这样的 Object 对象,但如果 Object 对象是从层的,其子级数据,好像也读取不到. func ...

  2. Dream------Hadoop--网络拓扑与Hadoop--摘抄

    两个节点在一个本地网络中被称为“彼此的近邻”是什么意思?在高容量数据处理中,限制因素是我们在节点间 传送数据的速率-----带宽很稀缺.这个想法便是将两个节点间的带宽作为距离的衡量标准.   衡量节点 ...

  3. innodb和myisam数据库文件存储详解以及mysql表空间

    数据库常用的两种引擎有Innodb和Myisam,关于二者的区别参考:https://www.cnblogs.com/qlqwjy/p/7965460.html 1.关于数据库的存储在两种引擎的存储是 ...

  4. 百度url解析Joe.Smith整理大全

    百度url解析Joe.Smith整理大全 百度url解析Joe.Smith整理大全...1 本文链接:http://blog.csdn.net/qq_26816591/article/details/ ...

  5. STS热部署,springboot项目中修改代码不用重新启动服务

    方法如下: 1.在pom文件中引入  devtools  依赖: <dependency> <groupId>org.springframework.boot</grou ...

  6. trove远程连接mongodb

    创建数据库 <pre> [root@a581c7388dca /]# trove database-create e50f3b40-5165-4ccc-af9f-c121089fd902 ...

  7. NET调用Com组件事例

    http://blog.csdn.net/shizhiyingnj/article/details/1507948 在程序设计中,往往通过键盘的某个按键来完成相关操作! 下面就来说明如何实现: 1.引 ...

  8. poj2056

    寻找向左凸的地方,每个左凸能让S数量-2.上边或下边如果是半个左凸的话则各对应-1 #include <cstdio> #include <cstring> #include ...

  9. H5新增语义化标签

    一.根据页面的结构,由div派生的标签. <header> <footer> <nav> 导航 在H4中导航栏一般用ul-li标签,H5中可以直接用<nav& ...

  10. mac zsh环境配置java_home环境变量

    用zsh,修改-/.zshrc 修改这些文件之后,重修打开terminal,配置不会丢 首先确保已经安装了jdk: ## check the present running java which ja ...