Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<queue>
- #include<vector>
- #include<set>
- #include<cmath>
- #include <map>
- #include<math.h>
- #include<cstring>
- #include<string>
- typedef long double ld;
- typedef long long ll;
- using namespace std;
- int powr[7];
- int dp[100003];
- void sds(int b, int k, int& c,int lim){
- int x, y;
- x = y = 0;
- for (int i = 0; i < lim; i++){
- int f = b % 10;
- //cout << f << 'f' << '\n';
- b = b / 10;
- if (i < k){
- x += f*powr[i];
- }
- else{
- y += f*powr[i - k];
- }
- }
- //cout << x << ' ' << y;
- c = x*y;
- //cout << "c=" << c << '\n';
- }
- int calc(int b){
- if (b/10==0)return 1;
- int ans = 0;
- if (dp[b] != -1)return dp[b];
- int lim = 0,tst=b;
- while (b){
- b /= 10;
- lim++;
- }b= tst;
- //cout << lim << '\n';
- for (int i = 1; i < lim ; ++i){
- int c;
- sds(b,i, c,lim);
- ans = max(ans, 1 + calc(c));
- }
- dp[b] = ans;
- return ans;
- }
- int main(){
- powr[0] = 1;
- for (int i = 1; i < 7; i++){
- powr[i] = powr[i - 1] * 10;
- }
- int a;
- memset(dp, -1, sizeof dp);
- int t;
- cin >> t;
- while (t--){
- cin >> a;
- cout << calc(a);
- if (t)cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement