#include <bits/stdc++.h>
using namespace std;
string s;
int d;
unsigned long long dp[20], t[20];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>s;
d=s.length();
for(int i=0; i<d; ++i)
t[i+1]=s[i]-'0';
dp[0]=1;
dp[1]=t[1]+1;
for(int i=2; i<=d; ++i)
{
dp[i]+=dp[i-1]*(t[i]+1);
if(t[i-1]==1 && t[i]<9)
{
dp[i]+=dp[i-2]*(9-t[i]);
}
}
cout<<dp[d];
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 30 31 | #include <bits/stdc++.h> using namespace std; string s; int d; unsigned long long dp[20], t[20]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>s; d=s.length(); for(int i=0; i<d; ++i) t[i+1]=s[i]-'0'; dp[0]=1; dp[1]=t[1]+1; for(int i=2; i<=d; ++i) { dp[i]+=dp[i-1]*(t[i]+1); if(t[i-1]==1 && t[i]<9) { dp[i]+=dp[i-2]*(9-t[i]); } } cout<<dp[d]; return 0; } |
English