ccbeginner

UVa Q11258

Dec 10th, 2019
115
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //UVa Q11258
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define int long long
  5.  
  6. int dp[201];
  7.  
  8. int32_t main(){
  9.     int t;
  10.     cin >> t;
  11.     while(t--){
  12.         memset(dp, 0, sizeof(dp));
  13.         string s;
  14.         cin >> s;
  15.         dp[0] = s[0]-'0';
  16.         for(unsigned i = 1; i < s.size(); ++i){
  17.             int num = 0;
  18.             for(int j = i, k = 1; j >= 0; --j, k *= 10){
  19.                 num += (s[j] - '0') * k;
  20.                 //cout << num << endl;
  21.                 if(num > INT_MAX)break;
  22.                 if(j > 0)dp[i] = max(dp[i], dp[j-1]+num);
  23.                 else dp[i] = max(dp[i], num);
  24.                 //if(j > 0)cout<<dp[j] << '+' << num << endl;
  25.             }
  26.         }
  27.         cout << dp[s.size()-1] << '\n';
  28.     }
  29.     return 0;
  30. }
RAW Paste Data