zoukankan      html  css  js  c++  java
  • HDU

    B-number

    A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- string "13" and can be divided by 13. For example, 130 and 2613 are wqb-numbers, but 143 and 2639 are not. Your task is to calculate how many wqb-numbers from 1 to n for a given integer n.

    InputProcess till EOF. In each line, there is one positive integer n(1 <= n <= 1000000000).OutputPrint each answer in a single line.Sample Input

    13
    100
    200
    1000

    Sample Output

    1
    1
    2
    2



    题意:满足含13且被13整除的个数。

    “不要62”的变式,这里要“13”,统计连续两位数的另一种处理方式。


    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    
    int a[12];
    int dp[12][2][2][15]; 
    
    ll dfs(int pos,int pre,int one,int sta,bool p,bool limit){
        
        if(pos==-1) return sta==0&&p;
        if(!limit&&dp[pos][one][p][sta]>-1) return dp[pos][one][p][sta];
        int up=limit?a[pos]:9;
        int cnt=0;
        for(int i=0;i<=up;i++){
            if(pre==1&&i==3) cnt+=dfs(pos-1,i,i==1,(sta*10+i)%13,true,limit&&i==a[pos]);
            else cnt+=dfs(pos-1,i,i==1,(sta*10+i)%13,p,limit&&i==a[pos]);
        }
        if(!limit) dp[pos][one][p][sta]=cnt;
        return cnt;
    }
    int solve(int x){
        int pos=0;
        while(x){
            a[pos++]=x%10;
            x/=10;
        }
        return dfs(pos-1,0,0,0,false,true);
    }
    int main()
    {
        int r;
        memset(dp,-1,sizeof(dp));
        while(~scanf("%d",&r)){
            printf("%d
    ",solve(r));
        }
        return 0;
    }
  • 相关阅读:
    java8 Stream排序字段为空排序方法
    SpringBoot使用token简单鉴权的具体实现方法
    性能调优
    TestNG最简单的测试
    TestNG异常测试
    TestNG中如何执行测试
    TestNG的基本注解
    TestNG介绍
    TestNG 环境搭建
    python第四课笔记
  • 原文地址:https://www.cnblogs.com/yzm10/p/10328613.html
Copyright © 2011-2022 走看看