• 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;
    }
  • 相关阅读:
    JFreeChart学习笔记
    Java基于JavaMail实现向QQ邮箱发送邮件遇到的问题
    JBPM入门
    eclipse jbmp 4.4 插件的安装及配置
    Redis开启远程登录连接
    springmvc @ResponseBody返回json 报406 not acceptable
    generatorConfiguration配置详解
    WCF、WebAPI、WCFREST、WebService之间的区别
    理解nodejs和react之间的关系
    DB2 sqlCode-668
  • 原文地址:https://www.cnblogs.com/yzm10/p/10328613.html
Copyright © 2020-2023  润新知