Advertisement
Josif_tepe

Untitled

Apr 24th, 2023
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <map>
  7. #include <stack>
  8. #include <set>
  9. using namespace std;
  10. const int maxn = 1005;
  11. typedef long long ll;
  12. int dp[maxn][maxn];
  13. ll pref_sum[maxn];
  14.  
  15.  
  16. int rec(int i, int j) {
  17.     for(int k = i; k < j; k++) {
  18.         if(pref_sum[k] * 2 == pref_sum[j] + pref_sum[i - 1]) {
  19.             return max(rec(i, k), rec(k + 1, j)) + 1;
  20.         }
  21.     }
  22.     return 0;
  23. }
  24. int main() {
  25.     ios_base::sync_with_stdio(false);
  26.     int t;
  27.     cin >> t;
  28.     while(t--) {
  29.         memset(pref_sum, 0, sizeof pref_sum);
  30.         int n;
  31.         cin >> n;
  32.         ll s = 0;
  33.         for(int i = 1 ; i <= n; i++) {
  34.             cin >> pref_sum[i];
  35.             pref_sum[i] += pref_sum[i - 1];
  36.         }
  37.         cout << rec(1, n) << endl;
  38.     }
  39.     return 0;
  40. }
  41. /*
  42.  5 9 7
  43. ...##....
  44. ..#.##..#
  45. ..#....##
  46. .##...#..
  47. ....#....
  48. WS?EE??
  49.  
  50.  
  51.  **/
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement