• HDU 3555 Bomb


    Bomb

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
    Total Submission(s): 10967    Accepted Submission(s): 3890


    Problem Description
    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?
     
    Input
    The 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.
     
    Output
    For each test case, output an integer indicating the final points of the power.
     
    Sample Input
    3
    1
    50
    500
     
    Sample Output
    0
    1
    15
     
    Hint
    From 1 to 500, the numbers that include the sub-sequence "49" are "49","149","249","349","449","490","491","492","493","494","495","496","497","498","499", so the answer is 15.
     
    Author
    fatboy_cw@WHU
     
    Source
     
    解题:数位dp,我就不说什么了
     
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long long LL;
     4 const int maxn = 21;
     5 LL dp[maxn][3];
     6 int b[maxn];
     7 LL dfs(int p,int st,bool flag){
     8     if(!p) return st == 2;
     9     if(flag && dp[p][st] != -1) return dp[p][st];
    10     int u = flag?9:b[p];
    11     LL ret = 0;
    12     for(int i = 0; i <= u; ++i){
    13         if(st == 1 && i == 9 || st == 2) ret += dfs(p-1,2,flag||(i < u));
    14         else if(i == 4) ret += dfs(p-1,1,flag||(i < u));
    15         else ret += dfs(p-1,0,flag||(i < u));
    16     }
    17     if(flag) dp[p][st] = ret;
    18     return ret;
    19 }
    20 LL solve(LL x){
    21     int len = 0;
    22     while(x){
    23         b[++len] = x%10;
    24         x /= 10;
    25     }
    26     return dfs(len,0,false);
    27 }
    28 int main(){
    29     memset(dp,-1,sizeof dp);
    30     int kase;
    31     scanf("%d",&kase);
    32     while(kase--){
    33         LL tmp;
    34         scanf("%I64d",&tmp);
    35         printf("%I64d
    ",solve(tmp));
    36     }
    37     return 0;
    38 }
    View Code
  • 相关阅读:
    JavaScript constructor prototyoe
    bootstrap固定响应式导航
    跨浏览器事件处理程序
    原生JS实现字符串分割
    关于css里的class和id
    js动态创建表格方法
    关于css的默认宽度
    js字符串大小写转换
    C++类的一个重要成员:静态成员(二)——静态成员的定义
    C++ 类的一个重要成员:静态成员(一)
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4782213.html
Copyright © 2020-2023  润新知