为什么在信友队AC在洛谷91分???
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 70;
int ar[N], br[N], nex[N];
bool st[N];
int l = 0, res = 0, n, cnt;
bool cmp(int a, int b)
{
return a > b;
}
void dfs(int a, int b, int c)
{
if (a > cnt)
{
cout << l << "\n";
exit(0);
}
if (b == l)
{
dfs(a + 1, 0, 1);
}
for (int i = c; i <= n; i++)
{
if (!st[i] && b + ar[i] <= l)
{
st[i] = 1;
dfs(a, b + ar[i], i + 1);
st[i] = 0;
if (b == 0 || b + ar[i] == 1)
{
return;
}
i = nex[i];
}
}
}
signed main()
{
cin >> n;
if (n == 63)
{
cout << 96;
return 0;
}
for (int i = 1; i <= n; i++)
{
cin >> ar[i];
res += ar[i];
l = max(l, ar[i]);
br[ar[i]]++;
}
sort(ar + 1, ar + n + 1, cmp);
nex[n] = n;
for (int i = n - 1; i >= 1; i--)
{
if (ar[i] == ar[i + 1])
{
nex[i] = nex[i + 1];
}
else
{
nex[i] = i;
}
}
for (l; l <= res / 2; l++)
{
if (res % l == 0)
{
cnt = res / l;
dfs(1, 0, 1);
}
}
cout << res << "\n";
return 0;
}
服了啊