我是靠谱客的博主 老迟到冰棍,这篇文章主要介绍[数位DP]Hdu 3555——Bomb,现在分享给大家,希望可以做个参考。

题目梗概

求不超过n的含 49 的数字的个数。

解题思路

数位DPSB题。

#include<cstdio>
#define LL long long
using namespace std;
LL n,f[25][15],x;
int a[25],len,t;
LL DFS(int len,int lst,int pd){
    if (len<1) return 1;
    if (!pd&&f[len][lst]!=0) return f[len][lst];
    int now;if (!pd) now=9;else now=a[len];
    LL num=0;
    for (int i=0;i<=now;i++)
    if (lst!=4||i!=9) num+=DFS(len-1,i,pd&&(i==now));
    if (!pd) f[len][lst]=num;
    return num;
}
int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%lld",&n);
        len=0;x=n;
        while(x>0){
            a[++len]=x%10;
            x/=10;
        }
        printf("%lldn",n+1-DFS(len,0,1));
    }
    return 0;
}

最后

以上就是老迟到冰棍最近收集整理的关于[数位DP]Hdu 3555——Bomb的全部内容,更多相关[数位DP]Hdu内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部