#include <bits/stdc++.h> using namespace std; #define FOR(i,x,y) for(int i=(int)(x);i<(int)(y);++i) #define FORE(i,x,y) for(int i=(int)(x);i<=(int)(y);++i) #define FORD(i,x,y) for(int i=(int)(x);i>=(int)(y);--i) #define PB push_back #define MP make_pair #define ST first #define ND second typedef long long ll; typedef pair<int,int> pii; ll n,m=0; ll a[100]; ll dp[100][2]; ll ile[100]; int main() { ios_base::sync_with_stdio(false);cin.tie(0); cin>>n; FORE(i,0,9)ile[i]=i+1; FORE(i,10,18)ile[i]=19-i; while(n>0){ a[m++]=n%10; n/=10; } dp[m][0]=1; dp[m][1]=0; FORD(i,m-1,0){ ll x=0; if(a[i+1]==1)x=dp[i+1][1]*ile[a[i+1]*10+a[i]]; dp[i][0]=x+dp[i+1][0]*ile[a[i]]; dp[i][1]=dp[i+1][0]; } cout<<dp[0][0]; 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 32 33 34 35 36 37 | #include <bits/stdc++.h> using namespace std; #define FOR(i,x,y) for(int i=(int)(x);i<(int)(y);++i) #define FORE(i,x,y) for(int i=(int)(x);i<=(int)(y);++i) #define FORD(i,x,y) for(int i=(int)(x);i>=(int)(y);--i) #define PB push_back #define MP make_pair #define ST first #define ND second typedef long long ll; typedef pair<int,int> pii; ll n,m=0; ll a[100]; ll dp[100][2]; ll ile[100]; int main() { ios_base::sync_with_stdio(false);cin.tie(0); cin>>n; FORE(i,0,9)ile[i]=i+1; FORE(i,10,18)ile[i]=19-i; while(n>0){ a[m++]=n%10; n/=10; } dp[m][0]=1; dp[m][1]=0; FORD(i,m-1,0){ ll x=0; if(a[i+1]==1)x=dp[i+1][1]*ile[a[i+1]*10+a[i]]; dp[i][0]=x+dp[i+1][0]*ile[a[i]]; dp[i][1]=dp[i+1][0]; } cout<<dp[0][0]; return 0; } |