zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    gotour源码阅读
    CPU知识
    GCC知识
    go/src/make.bash阅读
    Go的pprof使用
    CGI的一些知识点
    STM32——C语言数据类型
    css 学习资料
    项目管理实践教程
    js 格式验证总结
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4782213.html
Copyright © 2011-2022 走看看