zoukankan      html  css  js  c++  java
  • 【HDU 4722】 Good Numbers

    【题目链接】

                点击打开链接

    【算法】

              f[i][j]表示第i位,数位和对10取模余j的数的个数

              状态转移,计算答案都比较简单,笔者不再赘述

    【代码】

              

    #include<bits/stdc++.h>
    using namespace std;
    #define MAXL 20
    
    long long i,T,n,m;
    long long dp[MAXL][10],a[MAXL];
    
    template <typename T> inline void read(T &x) {
            long long f = 1; x = 0;
            char c = getchar();
            for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
            for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
            x *= f;
    }
    template <typename T> inline void write(T x) {
        if (x < 0) { putchar('-'); x = -x; }
        if (x > 9) write(x/10);
        putchar(x%10+'0');
    }
    template <typename T> inline void writeln(T x) {
        write(x);
        puts("");
    }
    inline void getdp() {
            long long i,j,k;
            dp[0][0] = 1;
            for (i = 1; i <= MAXL; i++) {
                    for (j = 0; j < 10; j++) {
                            for (k = 0; k < 10; k++) {
                                    dp[i][(j+k)%10] += dp[i-1][j];
                            }
                    }
            }    
    }
    inline long long calc(long long n) {
            long long i,j,ans = 0,sum = 0;
            a[0] = 0;
            while (n) {
                    a[++a[0]] = n % 10;
                    n /= 10;
            }        
            for (i = a[0]; i >= 1; i--) {
                    for (j = 0; j < a[i]; j++) {
                            ans += dp[i-1][(10-((sum+j)%10))%10]; 
                    }
                    sum = (sum + a[i]) % 10;
            }
            return ans;
    }
    
    int main() {
            
            getdp();
            
            read(T);
            for (i = 1; i <= T; i++) {
                    read(n); read(m);    
                    cout<< "Case #"<<i<<": "<<calc(m+1)-calc(n)<<endl;
            }
            
            return 0;
        
    }
  • 相关阅读:
    Java 概述
    快速开始
    Essential Java.《Java 编程要点》
    SpringBoot属性配置-第三章
    SpringBoot项目属性配置-第二章
    SpringBoot学习-第一章
    spring boot configuration annotation processor not found in classpath
    IntelliJ IDEA 2017 完美注册方法及破解方法
    springmvc-初次接触
    mybatis的多表联查
  • 原文地址:https://www.cnblogs.com/evenbao/p/9196367.html
Copyright © 2011-2022 走看看