HDU 4734 F[x] (数位dp)
来源:互联网 发布:java 游戏引擎 编辑:程序博客网 时间:2024/06/07 06:12
#include <stdio.h>#include<string.h>#include<algorithm>using namespace std;int a[20];int dp[20][6000];int p[50];int all;int dfs(int pos,int sta,bool limit){if(pos==-1)return 1;if(!limit&&dp[pos][sta]!=-1){return dp[pos][sta]; }int up=limit?a[pos]:9;int sum=0,i;for(i=0;i<=up;i++){int k=sta-i*p[pos];if(k<0) continue;sum+=dfs(pos-1,k,limit&&i==up);}if(!limit)dp[pos][sta]=sum;return sum;}int solve(int x){int cnt=0;while(x){a[cnt++]=x%10;x/=10;}return dfs(cnt-1,all,1);}int main(int argc, char *argv[]){int t,i,cs=1;scanf("%d",&t);memset(dp,-1,sizeof(dp));p[0]=1;for(i=1;i<30;i++){p[i]=p[i-1]*2;}while(t--){int A,B;while(scanf("%d %d",&A,&B)!=EOF){all=0;int cnt1=0;while(A){all+=(A%10)*p[cnt1++];A/=10;}printf("Case #%d: ",cs++);printf("%d\n",solve(B));}}return 0;}
Time Limit: 1000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6851 Accepted Submission(s): 2649
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)
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
30 1001 105 100
Sample Output
Case #1: 1Case #2: 2Case #3: 13
Source
阅读全文
0 0
- [HDU 4734]F(x)[数位DP]
- hdu 4734 F(x)(数位DP)
- 简单数位dp-hdu-4734-F(x)
- 【数位DP】 HDU 4734 F(x)
- hdu-4734-F(x)--数位dp
- hdu 4734 F(x) --- 数位dp
- hdu 4734 F(x) (数位dp)
- [数位dp] hdu 4734 F(x)
- hdu 4734 F(x)(数位dp)
- 【HDU】4734 F(x) 数位DP
- HDU 4734 F(x)(数位DP)
- HDU 4734 F(x) (数位DP)
- hdu 4734 F(x) 数位dp
- 【数位DP】 HDU 4734 F(x)
- HDU 4734 F(x)(数位DP)
- HDU 4734 F(X) 数位DP
- Hdu 4734 F(x) (数位dp)
- HDU 4734 F(x) (数位DP)
- Python踩坑之路-Python-3.6 安装pycrypto 2.6.1各种疑难杂症及解决方案
- 最小二乘回归
- 数据结构实验之图论六:村村通公路
- NOIP提高组2017小结
- spring基础
- HDU 4734 F[x] (数位dp)
- 【JavaScript学习】DOM操作技术
- 数据结构实验之图论三:判断可达性(DFS算法)
- 基于颜色分量HSV的图像分割:基于opencv的分割调试工具源码
- CodeForces
- java 线程的五种状态
- C++ bind
- C语言学习心得与体会1
- 阿里云 linux搭建git服务器