forked from jahid-hridoy/Code_Templates
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDigitDp Format
More file actions
57 lines (40 loc) · 921 Bytes
/
DigitDp Format
File metadata and controls
57 lines (40 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
#define int long long
int res, m, ans;
int f(int pos, int Small, int ok, vector<int>&v, vector<vector<vector<int>>>&dp) {
if (pos == m)return ok;
if (dp[pos][Small][ok] != -1)return dp[pos][Small][ok];
int l = 0, r = v[pos], val = 0;
if (Small)r = 9;
for (int j = l; j <= r; j++) {
val += f(pos + 1, Small | (j < r), ok | (j == 7), v, dp);
}
return dp[pos][Small][ok] = val;
}
void solve() {
int n;
cin >> n;
int s = n;
vector<int>v;
while (s) {
v.push_back(s % 10);
s /= 10;
}
m = v.size();
reverse(v.begin(), v.end());
vector<vector<vector<int>>>dp(11, vector<vector<int>>(2, vector<int>(2, -1)));
ans += n;
res += f(0, 0, 0, v, dp);
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
cout << ans - res << '\n';
return 0;
}