Advertisement
jeff69

splitting integers

Apr 30th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
4CS 1.12 KB | None | 0 0
  1. #include<iostream>
  2. #include<queue>
  3. #include<vector>
  4. #include<set>
  5. #include<cmath>
  6. #include <map>
  7. #include<math.h>
  8. #include<cstring>
  9. #include<string>
  10. typedef long double ld;
  11.  
  12. typedef long long ll;
  13. using namespace std;  
  14. int powr[7];
  15. int dp[100003];
  16. void sds(int b, int k, int& c,int lim){
  17.     int x, y;
  18.     x = y = 0;
  19.     for (int i = 0; i < lim; i++){
  20.         int f = b % 10;
  21.         //cout << f << 'f' << '\n';
  22.         b = b / 10;
  23.         if (i < k){
  24.             x += f*powr[i];
  25.         }
  26.         else{
  27.             y += f*powr[i - k];
  28.         }
  29.  
  30.     }
  31.     //cout << x << ' ' << y;
  32.     c = x*y;
  33.     //cout << "c=" << c << '\n';
  34. }
  35. int calc(int b){
  36.     if (b/10==0)return 1;
  37.     int ans = 0;
  38.     if (dp[b] != -1)return dp[b];
  39.     int lim = 0,tst=b;
  40.     while (b){
  41.         b /= 10;
  42.         lim++;
  43.     }b= tst;
  44.     //cout << lim << '\n';
  45.     for (int i = 1; i < lim ; ++i){
  46.         int c;
  47.         sds(b,i, c,lim);
  48.         ans = max(ans, 1 + calc(c));
  49.  
  50.     }
  51.     dp[b] = ans;
  52.     return ans;
  53. }
  54.  
  55. int main(){
  56.      
  57.     powr[0] = 1;
  58.     for (int i = 1; i < 7; i++){
  59.         powr[i] = powr[i - 1] * 10;
  60.     }
  61.      
  62.     int a;
  63.     memset(dp, -1, sizeof dp);
  64.     int t;
  65.     cin >> t;
  66.     while (t--){
  67.         cin >> a;
  68.         cout << calc(a);
  69.    
  70.         if (t)cout << endl;
  71.     }
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement