#include <bits/stdc++.h> using namespace std; string a; const int N = 100; ulong long dp[N+7]; int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); cin>>a; dp[0] = 1; dp[1] = 1; a = '0'+a; for(uint i =2 ;i<1+a.size();i++) { //dp[i] = dp[i-1]*(a[i-1]-'0' + 1)*((10*(a[i-2]-'0') + (a[i-1]-'0')>=19) or (10*(a[i-2]-'0') + (a[i-1]-'0')<10) )+ (10*(a[i-2]-'0') + (a[i-1]-'0')<19)*dp[i-2]*(10*(a[i-2]-'0') + (a[i-1]-'0') +1); long long pom = 10*(a[i-2]-'0') + (a[i-1]-'0'); dp[i] = (dp[i-1]-2*dp[i-2]*(pom<19 and pom>=10))*(a[i-1]-'0' + 1) + (pom<19 and pom>=10)*dp[i-2]*(pom +1); //cout<<(dp[i-1]-dp[i-2]*(pom<19 and pom>=10))*(a[i-1]-'0' + 1)<<" "<<(pom<19 and pom>=10)*dp[i-2]*(pom +1)<<" "<<dp[i]<<" "<<i-2<<"\n"; } cout<<dp[a.size()]; }
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 | #include <bits/stdc++.h> using namespace std; string a; const int N = 100; ulong long dp[N+7]; int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); cin>>a; dp[0] = 1; dp[1] = 1; a = '0'+a; for(uint i =2 ;i<1+a.size();i++) { //dp[i] = dp[i-1]*(a[i-1]-'0' + 1)*((10*(a[i-2]-'0') + (a[i-1]-'0')>=19) or (10*(a[i-2]-'0') + (a[i-1]-'0')<10) )+ (10*(a[i-2]-'0') + (a[i-1]-'0')<19)*dp[i-2]*(10*(a[i-2]-'0') + (a[i-1]-'0') +1); long long pom = 10*(a[i-2]-'0') + (a[i-1]-'0'); dp[i] = (dp[i-1]-2*dp[i-2]*(pom<19 and pom>=10))*(a[i-1]-'0' + 1) + (pom<19 and pom>=10)*dp[i-2]*(pom +1); //cout<<(dp[i-1]-dp[i-2]*(pom<19 and pom>=10))*(a[i-1]-'0' + 1)<<" "<<(pom<19 and pom>=10)*dp[i-2]*(pom +1)<<" "<<dp[i]<<" "<<i-2<<"\n"; } cout<<dp[a.size()]; } |