// UVa 11258 - String Partition #include <iostream> #include <string> #include <string.h> using namespace std; #define uint unsigned long long #define lim 2147483648 int main() { int cases; for (cin >> cases; cases; cases--) { string st; cin >> st; int n = st.length(); uint T[200]; memset(T, 0, sizeof(T)); for (int i = 0; i < n; i++) { uint e = 1, right = 0; for (int j = i; j >= 0; j--) { right += (st[j] - '0') * e; if (right >= lim) break; if (st[j] != '0' || i == j) { if (j > 0) T[i] = max(T[i], T[j - 1] + right); else T[i] = max(T[i], right); } e *= 10; } } cout << T[n - 1] << endl; } return 0; }
Friday, December 4, 2015
UVa 11258 - String Partition
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment