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 )

  • 相关阅读:
    android 开机启动
    android 获取lanucher 列表
    原创高端影楼人像专业磨皮法教程详解 附PSD源码
    [转]在SQLPLUS启动和停止Oracle数据库
    挑印刷时间最新的地图!
    Eclipse3.2下进行ArcGIS Server 9.2 Java WebADF开发手记 Eclipse使用技巧
    [藏]常用的匹配正则表达式和实例
    [藏]C# 中的常用正则表达式总结
    [转]使用uDig制作geoserver中需要的style
    [转]geoserver与OpenLayers配置入门
  • 原文地址:https://www.cnblogs.com/CKboss/p/3350817.html
Copyright © 2011-2022 走看看