#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define ST first #define ND second #define PB push_back int solve(string s) { vector<ll> dp (30); dp[0] = 1; for(int i=1; i <= s.size(); i++) { char c = s[s.size()-i]; if(c == '1' && i > 1) { char d = s[s.size()-i+1]; ll num = 10+(d-48); ll mult = min(num+1, 19-num); dp[i]+= mult*dp[i-2]; } dp[i]+= (c-47)*dp[i-1]; } return dp[s.size()]; } int main() { ios_base::sync_with_stdio(0); string s; cin >> s; cout << solve(s) << "\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 27 28 29 30 31 32 | #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define ST first #define ND second #define PB push_back int solve(string s) { vector<ll> dp (30); dp[0] = 1; for(int i=1; i <= s.size(); i++) { char c = s[s.size()-i]; if(c == '1' && i > 1) { char d = s[s.size()-i+1]; ll num = 10+(d-48); ll mult = min(num+1, 19-num); dp[i]+= mult*dp[i-2]; } dp[i]+= (c-47)*dp[i-1]; } return dp[s.size()]; } int main() { ios_base::sync_with_stdio(0); string s; cin >> s; cout << solve(s) << "\n"; } |