#include<bits/stdc++.h> using namespace std; int n,t[20],x; string s; unsigned long long dp[25]; int main() { cin>>s; n = s.size(); s = '%' + s; for(int i = 0;i < 10; ++i) for(int j = 0;j < 10; ++j) t[i + j]++; dp[n] = t[s[n] - '0']; x = (s[n - 1] - '0') * 10 + s[n] - '0'; if(x > 9 && x < 19) dp[n - 1] = t[x]; dp[n - 1] += dp[n] * t[s[n - 1] - '0']; for(int i = n - 2;i > 0; --i) { x = (s[i] - '0') * 10 + s[i + 1] - '0'; if(x > 9 && x < 19) dp[i] = dp[i + 2] * t[x]; dp[i] += dp[i + 1] * t[s[i] - '0']; } cout<<dp[1]; return 0; }
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 | #include<bits/stdc++.h> using namespace std; int n,t[20],x; string s; unsigned long long dp[25]; int main() { cin>>s; n = s.size(); s = '%' + s; for(int i = 0;i < 10; ++i) for(int j = 0;j < 10; ++j) t[i + j]++; dp[n] = t[s[n] - '0']; x = (s[n - 1] - '0') * 10 + s[n] - '0'; if(x > 9 && x < 19) dp[n - 1] = t[x]; dp[n - 1] += dp[n] * t[s[n - 1] - '0']; for(int i = n - 2;i > 0; --i) { x = (s[i] - '0') * 10 + s[i + 1] - '0'; if(x > 9 && x < 19) dp[i] = dp[i + 2] * t[x]; dp[i] += dp[i + 1] * t[s[i] - '0']; } cout<<dp[1]; return 0; } |