zoukankan      html  css  js  c++  java
  • HDOJ 4389 X mod f(x)


    数位DP........

    X mod f(x)

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 1403    Accepted Submission(s): 599


    Problem Description
    Here is a function f(x):
       int f ( int x ) {
        if ( x == 0 ) return 0;
        return f ( x / 10 ) + x % 10;
       }

       Now, you want to know, in a given interval [A, B] (1 <= A <= B <= 109), how many integer x that mod f(x) equal to 0.
     

    Input
       The first line has an integer T (1 <= T <= 50), indicate the number of test cases.
       Each test case has two integers A, B.
     

    Output
       For each test case, output only one line containing the case number and an integer indicated the number of x.
     

    Sample Input
    2
    1 10
    11 20
     

    Sample Output
    Case 1: 10
    Case 2: 3
     

    Author
    WHU
     

    Source
     

    Recommend
    zhuyuanchen520
     
     

    #include <iostream>
    #include <cstdio>
    #include <cstring>

    using namespace std;

    int bit[10],dp[10][82][82][82];

    int dfs(int pos,int sum,int mod,int res,bool limit)
    {
        if(mod>81||sum>mod) return 0;
        if(pos==-1return sum==mod&&res==0;
        if(!limit&&~dp[pos][sum][mod][res])
            return dp[pos][sum][mod][res];
        int end=limit?bit[pos]:9,ans=0;
        for(int i=0;i<=end;i++)
        {
            ans+=dfs(pos-1,sum+i,mod,(res*10+i)%mod,limit&&i==end);
        }
        if(!limit)
            dp[pos][sum][mod][res]=ans;
        return ans;
    }

    int calu(int x)
    {
        int pos=0,ans=0;;
        while(x)
        {
            bit[pos++]=x%10;
            x/=10;
        }
        for(int i=1;i<=pos*9;i++)
        {
            ans+=dfs(pos-1,0,i,0,true);
        }
        return ans;
    }

    int main()
    {
        int t,a,b,cas=1;
        memset(dp,-1,sizeof(dp));
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d%d",&a,&b);
            printf("Case %d: %d ",cas++,calu(b)-calu(a-1));
        }
        return 0;
    }
    * This source code was highlighted by YcdoiT. ( style: Codeblocks )

  • 相关阅读:
    CAP
    plugins for ST3 to frontend
    OAuth 2.0 详解
    Git SSH生成
    Android FrameWork 学习之Android 系统源码调试
    node.js安装步骤
    数据结构-- 队列 循环与顺序
    jsp之认识 servlet (基础、工作原理、容器请求处理)
    android 蓝牙开发---与蓝牙模块进行通讯 基于eclipse项目
    Android 仿微信调用第三方应用导航(百度,高德、腾讯)
  • 原文地址:https://www.cnblogs.com/CKboss/p/3350817.html
Copyright © 2011-2022 走看看