#include <bits/stdc++.h>
#define int long long
#define all(v) v.begin(), v.end()
using namespace std;
const int sz = 3e3 + 1, inf = 1e18;
int n, a[sz], dp[sz][sz];
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 0; i < n; i++)
{
cin >> a[i];
}
int ans = 0;
for(int bt = 0; bt < (1 << n); bt++)
{
cout << bt << " : ";
int prv = 0, cnt = 0;
for(int i = 0; i < n && cnt >= 0; i++)
{
int x = ((1 << i) & bt);
int j = i + 1, sm = a[i];
while(j < n && !!((1 << j) & bt) == x)
{
sm += a[j];
j++;
}
if(sm >= prv)
{
prv = sm;
cnt++;
}
else cnt = -1;
i = j - 1;
}
cout << cnt << endl;
ans = max(ans, cnt);
}
// 10011
// 16 + 2 + 1
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |