#include <bits/stdc++.h> using namespace std; #define SZ(x) ((int)(x).size()) typedef long long ll; int main() { string str; cin >> str; int sz = SZ(str); vector<int> s(sz); for (int i = 0; i < sz; i++) s[i] = str[sz-i-1] - '0'; vector<ll> dp(sz); dp[0] = s[0]+1; dp[1] = dp[0] * (s[1]+1); if (s[1] == 1) dp[1] += 9-s[0]; for (int i = 2; i < sz; i++) { dp[i] = dp[i-1] * (s[i]+1); if (s[i] == 1) dp[i] += (9-s[i-1])*dp[i-2]; } cout << dp[sz-1] << "\n"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <bits/stdc++.h> using namespace std; #define SZ(x) ((int)(x).size()) typedef long long ll; int main() { string str; cin >> str; int sz = SZ(str); vector<int> s(sz); for (int i = 0; i < sz; i++) s[i] = str[sz-i-1] - '0'; vector<ll> dp(sz); dp[0] = s[0]+1; dp[1] = dp[0] * (s[1]+1); if (s[1] == 1) dp[1] += 9-s[0]; for (int i = 2; i < sz; i++) { dp[i] = dp[i-1] * (s[i]+1); if (s[i] == 1) dp[i] += (9-s[i-1])*dp[i-2]; } cout << dp[sz-1] << "\n"; } |