#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> pos(30, 0);
void getPos()
{
for(int i=0; i<10; i++)
for(int j=0; j<10;j++)
pos[i+j]++;
}
int n;
vector<int> num(30,0);
void getNum(int k)
{
for(int i=29; i>=0; i--)
{
num[i] = k%10;
k/=10;
}
}
vector<int> res(30, 1);
int getDouble(int i)
{
// 10*(i-1) + i
return 10*num[i-1] + num[i];
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
getPos();
getNum(n);
for(int i=2; i<res.size(); i++)
{
res[i] = res[i-1] * pos[num[i]];
if(getDouble(i) > 9 && getDouble(i) < 19)
res[i] += res[i-2] * pos[getDouble(i)];
}
cout << res[29];
}
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #include <iostream> #include <vector> #include <algorithm> using namespace std; vector<int> pos(30, 0); void getPos() { for(int i=0; i<10; i++) for(int j=0; j<10;j++) pos[i+j]++; } int n; vector<int> num(30,0); void getNum(int k) { for(int i=29; i>=0; i--) { num[i] = k%10; k/=10; } } vector<int> res(30, 1); int getDouble(int i) { // 10*(i-1) + i return 10*num[i-1] + num[i]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; getPos(); getNum(n); for(int i=2; i<res.size(); i++) { res[i] = res[i-1] * pos[num[i]]; if(getDouble(i) > 9 && getDouble(i) < 19) res[i] += res[i-2] * pos[getDouble(i)]; } cout << res[29]; } |
English