码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-10-31 12:49:59      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:sizeof   name   target   col   vector   ref   数位dp   efi   stream   

题意: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;
}

 

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

标签:sizeof   name   target   col   vector   ref   数位dp   efi   stream   

原文地址:http://www.cnblogs.com/a719525932/p/7760511.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!