#include <bits/stdc++.h> using namespace std; uint64_t calc(uint64_t n) { vector<int> digs; string s = to_string(n); vector<uint64_t> dp(s.size()); for(int i = 0; i < s.size(); ++i) { int dig = s[i] - '0'; dp[i] += (i > 0 ? dp[i - 1] : 1llu) * (dig + 1); if(i > 0) { int two = dig + (s[i - 1] - '0') * 10; if(two > 9 && two < 19) { dp[i] += (i > 1 ? dp[i - 2] : 1llu) * (19 - two); } } } return dp[s.size() - 1]; } int main() { uint64_t n; cin >> n; cout << calc(n); }
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 | #include <bits/stdc++.h> using namespace std; uint64_t calc(uint64_t n) { vector<int> digs; string s = to_string(n); vector<uint64_t> dp(s.size()); for(int i = 0; i < s.size(); ++i) { int dig = s[i] - '0'; dp[i] += (i > 0 ? dp[i - 1] : 1llu) * (dig + 1); if(i > 0) { int two = dig + (s[i - 1] - '0') * 10; if(two > 9 && two < 19) { dp[i] += (i > 1 ? dp[i - 2] : 1llu) * (19 - two); } } } return dp[s.size() - 1]; } int main() { uint64_t n; cin >> n; cout << calc(n); } |