首页 > 其他 > 详细

Bomb HDU - 3555

时间:2018-09-09 22:37:42      阅读:209      评论:0      收藏:0      [点我收藏+]

Bomb HDU - 3555

 

求1~n中含有49数的个数

#include<bits/stdc++.h>

#define LL long long
using namespace std;

LL T,x,dp[50][50],shu[50];

LL dfs(LL pos,LL x,bool ok,bool limit){
    if(!pos) return ok;
    if(!limit&&dp[pos][x]) return dp[pos][x];
    LL cnt=0,up=limit?shu[pos]:9;
    for(LL i=0;i<=up;i++)
    {
        bool flg=false;
        if(x==4&&i==9) flg=true;
        if(ok) flg=true;
        cnt+=dfs(pos-1,i,flg,limit&&shu[pos]==i);
    }
    if(!limit) dp[pos][x]=cnt;
    return cnt;
}

LL slove(LL x){
    LL k=0;
    while(x){
        shu[++k]=x%10;
        x/=10;
    }
    return dfs(k,0,0,true);
}

int main()
{
    scanf("%lld",&T);
    while(T--){
        scanf("%lld",&x);
        printf("%lld",slove(x));
        if(T) puts("");
    }
    return 0;
}

 

Bomb HDU - 3555

原文:https://www.cnblogs.com/song-/p/9615533.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!