zoukankan      html  css  js  c++  java
  • HDU3555 Bomb 数位DP第一题

    The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If the current number sequence includes the sub-sequence "49", the power of the blast would add one point. 
    Now the counter-terrorist knows the number N. They want to know the final points of the power. Can you help them? 

    InputThe first line of input consists of an integer T (1 <= T <= 10000), indicating the number of test cases. For each test case, there will be an integer N (1 <= N <= 2^63-1) as the description. 

    The input terminates by end of file marker. 
    OutputFor each test case, output an integer indicating the final points of the power.Sample Input

    3
    1
    50
    500

    Sample Output

    0
    1
    15

    #include<cstdio>
    #include<cstdlib>
    #include<iostream>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    #define LL long long
    const int N=30;
    LL dp[N][2][2][2],n,ans;
    int a[N],cnt;
    void _divide(LL v){
        cnt=0;
        while(v){
            a[++cnt]=v%10;
            v/=10;
        }return ;
    }
    LL _dfs(int pos,bool limit,bool pre,bool stat)
    {
         if(pos==0) return stat;
         LL tmp=0;
         if(!limit&&dp[pos][limit][pre][stat]) return dp[pos][limit][pre][stat];
         int Up=limit?a[pos]:9;
         for(int i=0;i<=Up;i++)
             tmp+=_dfs(pos-1,limit&&i==Up,i==4,stat||(pre&&i==9));
         dp[pos][limit][pre][stat]=tmp;
         if(tmp>ans) ans=tmp;
         return tmp;
    }
    int main()
    {
        int i,T;
        scanf("%d",&T);
        while(T--){
            memset(dp,0,sizeof(dp));
            scanf("%lld",&n);
            _divide(n);
            printf("lld
    ",_dfs(cnt,true,false,false));
        }
        return 0;
    }
    View Code
  • 相关阅读:
    sql order by 结合case when then
    若sql语句中order by指定了多个字段,怎么排序?
    sql 按字段指定值排序
    mybatis Condition查询
    java.lang.OutOfMemoryError: GC overhead limit exceeded
    Could not open JDBC Connection for transaction
    Lock wait timeout exceeded; try restarting transaction
    [转载]Windows x64下配置ffmpeg的方法
    java第七节 IO
    mysql触发器 学习
  • 原文地址:https://www.cnblogs.com/hua-dong/p/7765361.html
Copyright © 2011-2022 走看看