HDU 4734 F(x)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4734

题意:对于一个n位的十进制数字x=(AnAn-1An-2 ... A2A1),定义 F(x)=An*2n-1+An-1*2n-2+ ...+A2*2+A1*1。给出A、B,求在[0,B]之间有多少数字满足F(x)<=F(A)?

思路:数位DP。f[dep][x]表示到达dep剩余为x的方案数。

i64 n,m;
i64 f[25][N];
int a[25],num;

i64 Sum;

i64 DFS(int dep,int flag,int cur)
{
    if(cur<0) return 0;
    if(dep==-1) return 1;
    if(!flag&&f[dep][cur]!=-1) return f[dep][cur];
    int M=flag?a[dep]:9;
    i64 ans=0,i;
    for(i=0;i<=M;i++)
    {
        ans+=DFS(dep-1,flag&&i==M,cur-i*(1<<dep));
    }
    if(!flag) f[dep][cur]=ans;
    return ans;
}

i64 cal()
{
    num=0;
    while(n) a[num++]=n%10,n/=10;
    Sum=0;
    int i,j;
    FOR0(i,num) Sum+=a[i]*(1<<i);
    num=0;
    while(m) a[num++]=m%10,m/=10;
    return DFS(num-1,1,Sum);
}

int main()
{
    clr(f,-1);
    int num=0;
    rush()
    {
        scanf("%I64d%I64d",&n,&m);
        printf("Case #%d: %I64d\n",++num,cal());
    }
}

HDU 4734 F(x),布布扣,bubuko.com

时间: 2024-11-03 22:19:18

HDU 4734 F(x)的相关文章

HDU - 4734 F(x) (2013成都网络赛,数位DP)

题意:求0-B的满足<=F[A]的所有可能 思路:数位DP,记忆化搜索 #include <iostream> #include <cstring> #include <algorithm> #include <cstdio> using namespace std; int A, B; int dp[20][200000]; int bit[20]; int dfs(int cur, int num, int flag) { if (cur == -

HDU 4734——F(x)

HDU 4734——F(x) 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4734 题意:数i在0~B的范围内,求F(i)小于F(A)的个数 F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1 先把F(A)算出来=tot,然后按位计算,如果num(当前F(pos)<=tot,方案数+1 返回1,如果num>tot,返回0) dp[pos][num] 的状态表示为dp[当前第几位][最大值t

hdu 4734 F(x)(数位dp+优化)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4734 题意:我们定义十进制数x的权值为f(x) = a(n)*2^(n-1)+a(n-1)*2(n-2)+...a(2)*2+a(1)*1,a(i)表示十进制数x中第i位的数字. 题目给出a,b,求出0~b有多少个不大于f(a)的数 显然这题可以设这样的dp dp[len][count]表示前len位权值为count的有多少,然后显然的在len==0时return count>=f(a); 但是这样

HDU 4734 F(x)(数位DP)

Description For a decimal number x with n digits (A nA n-1A n-2 ... A 2A 1), we define its weight as F(x) = A n * 2 n-1 + A n-1 * 2 n-2 + ... + A 2 * 2 + A1 * 1. Now you are given two numbers A and B, please calculate how many numbers are there betwe

HDU 4734 —— F(x)

F(x) Time Limit:500MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description For a decimal number x with n digits (A nA n-1A n-2 ... A 2A 1), we define its weight as F(x) = A n * 2 n-1 + A n-1 * 2 n-2 + ... + A 2 * 2 + A 1 * 1. Now yo

HDU 4734 F(x) (数位DP,基础)

题意:  一个非负整数的十进制位是这样的 (AnAn-1An-2 ... A2A1),定义F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1.给出A和B,问[0,B]中有几个整数x的F(x)值<=F(A)? 思路: 算一下就知道F(x)值不会超过512*9,而B仅仅有8位十进制数,那么8*512*9就可以算出所有的统计了.对于每个询问,先计算F(A)的值,然后统计小于此值有几个就行了.统计的复杂度也是很低的.若是以前缀和来统计后面的个数的

HDU - 4734 F(x) (2013成都网络游戏,数字DP)

意甲冠军:求0-B见面<=F[A]所有可能的 思维:数字DP,内存搜索 #include <iostream> #include <cstring> #include <algorithm> #include <cstdio> using namespace std; int A, B; int dp[20][200000]; int bit[20]; int dfs(int cur, int num, int flag) { if (cur == -

HDU 4734 F(x) (数位DP)

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

HDU - 4734 F(x) (数位DP)

For a decimal number x with n digits (A nA n-1A n-2 ... A 2A 1), we define its weight as F(x) = A n * 2 n-1 + A n-1 * 2 n-2 + ... + A 2 * 2 + A 1 * 1. Now you are given two numbers A and B, please calculate how many numbers are there between 0 and B,