hdu3555 Bomb (判断子串是否出现49) 数位dp

题意:http://acm.hdu.edu.cn/showproblem.php?pid=3555

比不要62还要简单  只不过在long long 上面注意些

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<vector>
#include<math.h>
#include<string>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define N 106
#define Lson rood<<1
#define Rson rood<<1|1
LL dp[63][11][3],d[63];///大数一定要用LL 避免出错也可用LL
LL dfs(int now,int up,int falg,int fp)
{
    if(now==1) return falg;
    if(!fp&&dp[now][up][falg]!=-1) return dp[now][up][falg];
    LL ans=0;
    int ma=fp?d[now-1]:9;
    for(int i=0;i<=ma;i++)///标记是否出现49
        ans+=dfs(now-1,i,falg||(up==4&&i==9),fp&&ma==i);
    if(!fp&&dp[now][up][falg]==-1) dp[now][up][falg]=ans;
    return ans;
}
LL calc(LL x)
{
    LL xxx=x;
    int len=0;
    while(xxx)
    {
        d[++len]=xxx%10;
        xxx/=10;
    }
    LL sum=0;
    for(int i=0;i<=d[len];i++)
        sum+=dfs(len,i,0,i==d[len]);
    return sum;
}
int main()
{
    int T;
    LL n;
    scanf("%d",&T);
    memset(dp,-1,sizeof(dp));
    while(T--)
    {
        scanf("%lld",&n);
        printf("%lld\n",calc(n));
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/a719525932/p/7760511.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值