zoukankan      html  css  js  c++  java
  • hdu 4389 X mod f(x) 数位dp

    X mod f(x)

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)


    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
    dp进阶之路写法;
    或者分块打表;
    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<set>
    #include<map>
    using namespace std;
    #define ll long long
    #define pi (4*atan(1.0))
    #define eps 1e-4
    #define bug(x)  cout<<"bug"<<x<<endl;
    const int N=1e5+10,M=1e6+10,inf=2147483647;
    const ll INF=1e18+10,mod=2147493647;
    int f[11][83][83][83],bit[11];
    int dp(int pos,int sum,int m,int p,int flag)
    {
        if(pos==0)return (sum==p&&m==0);
        if(flag&&f[pos][sum][m][p]!=-1)return f[pos][sum][m][p];
        int x=flag?9:bit[pos];
        int ans=0;
        for(int i=0;i<=x;i++)
        {
            ans+=dp(pos-1,sum+i,(m*10+i)%p,p,flag||i<x);
        }
        if(flag)f[pos][sum][m][p]=ans;
        return ans;
    }
    int getans(int x,int p)
    {
        int len=0;
        while(x)
        {
            bit[++len]=x%10;
            x/=10;
        }
        return dp(len,0,0,p,0);
    }
    int main()
    {
        int T,cas=1;
        memset(f,-1,sizeof(f));
        scanf("%d",&T);
        while(T--)
        {
            int l,r;
            scanf("%d%d",&l,&r);
            int ans=0;
            for(int i=1;i<=81;i++)
                ans+=getans(r,i)-getans(l-1,i);
            printf("Case %d: %d
    ",cas++,ans);
        }
        return 0;
    }
     
  • 相关阅读:
    problem in Sourcetree
    Get started with Sourcetree
    IIS application pool access desktop denied
    结构型模式 适配器模式
    结构型模式 装饰模式
    结构型模式 代理模式
    创建型模式 原型模式
    创建型模式 建造者模式
    创建型模式 抽象工厂
    设计模式的六大原则
  • 原文地址:https://www.cnblogs.com/jhz033/p/6591145.html
Copyright © 2011-2022 走看看