Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- typedef long long ll;
- const int maxn = 20005;
- ll pref_sum[maxn];
- ll query(int i, int j) {
- if(i == 0) {
- return pref_sum[j];
- }
- return pref_sum[j] - pref_sum[i - 1];
- }
- int rec(int L, int R) {
- for(int i = L; i < R; i++) {
- if(pref_sum[i] * 2 == pref_sum[R] + pref_sum[L - 1]) {
- return max(rec(L, i), rec(i + 1, R)) + 1;
- }
- }
- return 0;
- }
- int main() {
- int t;
- cin >> t;
- while(t--) {
- int n;
- cin >> n;
- memset(pref_sum, 0, sizeof pref_sum);
- ll sum = 0;
- for(int i = 0; i < n; i++) {
- int x;
- cin >> x;
- sum += x;
- pref_sum[i] = sum;
- }
- cout << rec(0, n - 1) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement