[HDOJ3555]Bomb(数位DP)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555

同理不要62,这回是要求带49的数,那么先求出不带49的,再减去。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 #define fr first
 4 #define sc second
 5 #define cl clear
 6 #define BUG puts("here!!!")
 7 #define W(a) while(a--)
 8 #define pb(a) push_back(a)
 9 #define Rint(a) scanf("%d", &a)
10 #define Rll(a) scanf("%I64d", &a)
11 #define Rs(a) scanf("%s", a)
12 #define Cin(a) cin >> a
13 #define FRead() freopen("in", "r", stdin)
14 #define FWrite() freopen("out", "w", stdout)
15 #define Rep(i, len) for(int i = 0; i < (len); i++)
16 #define For(i, a, len) for(int i = (a); i < (len); i++)
17 #define Cls(a) memset((a), 0, sizeof(a))
18 #define Clr(a, x) memset((a), (x), sizeof(a))
19 #define Full(a) memset((a), 0x7f7f7f, sizeof(a))
20 #define lrt rt << 1
21 #define rrt rt << 1 | 1
22 #define pi 3.14159265359
23 #define RT return
24 #define lowbit(x) x & (-x)
25 #define onecnt(x) __builtin_popcount(x)
26 typedef long long LL;
27 typedef long double LD;
28 typedef unsigned long long ULL;
29 typedef pair<int, int> pii;
30 typedef pair<string, int> psi;
31 typedef pair<LL, LL> pll;
32 typedef map<string, int> msi;
33 typedef vector<int> vi;
34 typedef vector<LL> vl;
35 typedef vector<vl> vvl;
36 typedef vector<bool> vb;
37
38 const int maxn = 25;
39
40 LL digit[maxn];
41 LL dp[maxn][2];
42
43 LL dfs(int l, bool num, bool jud) {
44   if(l == 0) return dp[l][num] = 1;
45   if(!jud && ~dp[l][num]) return dp[l][num];
46   LL ret = 0;
47   int nex = jud ? digit[l] : 9;
48   Rep(i, nex+1) {
49     if(num && i == 9) continue;
50     ret += dfs(l-1, i==4, jud&&i==nex);
51   }
52   if(!jud) dp[l][num] = ret;
53   return ret;
54 }
55
56 LL f(LL num) {
57   int pos = 0;
58   while(num) {
59     digit[++pos] = num % 10;
60     num /= 10;
61   }
62   return dfs(pos, false, true);
63 }
64
65 LL n;
66
67 signed main() {
68   //FRead();
69   Clr(dp, -1);
70   int T;
71   Rint(T);
72   W(T) {
73     cin >> n;
74     cout << n - f(n) + 1 << endl;
75   }
76   RT 0;
77 }
时间: 2024-08-19 08:58:37

[HDOJ3555]Bomb(数位DP)的相关文章

[ACM] hdu 3555 Bomb (数位DP,统计1-N中含有“49”的总数)

Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 7187 Accepted Submission(s): 2512 Problem Description The counter-terrorists found a time bomb in the dust. But this time the terrorists impro

hdu---(3555)Bomb(数位dp(入门))

Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 7921    Accepted Submission(s): 2778 Problem Description The counter-terrorists found a time bomb in the dust. But this time the terrorists

hud 3555 Bomb 数位dp

Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 19122    Accepted Submission(s): 7068 Problem Description The counter-terrorists found a time bomb in the dust. But this time the terrorist

hdu3555 Bomb(数位dp)

Bomb                                                                                     Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)                                                                             

HDU 3555 Bomb (数位DP)

数位dp,主要用来解决统计满足某类特殊关系或有某些特点的区间内的数的个数,它是按位来进行计数统计的,可以保存子状态,速度较快.数位dp做多了后,套路基本上都差不多,关键把要保存的状态给抽象出来,保存下来. 简介: 顾名思义,所谓的数位DP就是按照数字的个,十,百,千--位数进行的DP.数位DP的题目有着非常明显的性质: 询问[l,r]的区间内,有多少的数字满足某个性质 做法根据前缀和的思想,求出[0,l-1]和[0,r]中满足性质的数的个数,然后相减即可. 算法核心: 关于数位DP,貌似写法还是

HDU 3555 Bomb(数位DP)

Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone' (also known as 'Rock, Paper, Scissors', 'Ro, Sham, Bo', and a host of other names) in order to make arbitrary decisions such as who gets

hdu3555 Bomb (数位dp入门题)

Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 19698    Accepted Submission(s): 7311 Problem Description The counter-terrorists found a time bomb in the dust. But this time the terrorists

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

hdu3555 Bomb(数位dp)

题目传送门 Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 23059    Accepted Submission(s): 8673 Problem Description The counter-terrorists found a time bomb in the dust. But this time the terr

hdu 3555 Bomb(数位dp)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 题目大意:就是给你一个数n,判断从0到n有多少个数含有数字49...... 是不是觉得跟hdu2089很相似呀... 思路:跟hdu2089一样的,注意给出的数比较大,所以这儿用__int64  .... code: #include<cstdio> #include<iostream> #include<cstring> #include<algorithm&