33 pts 求调
查看原帖
33 pts 求调
912750
CarrotMeow楼主2023/4/10 13:34

是不是要特判 >50> 50 的情况啊……

#include <bits/stdc++.h>
using namespace std;

const int N = 70;
int n, d, cnt, mxa, a[N], l[N], p[N];

void dfs(int x, int k, int s) {
    //     没拼的   长棍  最短短棍
    if (!x) dfs(d, k - 1, a[n]);
    else {
        if (!k) printf("%d", d), exit(0);
        s = min(s, x);
        while (s && !l[s]) --s;
        while (s) {
            if (l[s]) {
                --l[s];
                dfs(x - s, k, s);
                ++l[s];
                if (x == s || x == d) return;
            }
            s = p[s];
        }
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]), cnt += a[i], ++l[a[i]];
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; ++i)
        if (a[i] != a[i + 1]) p[a[i]] = a[i - 1];
    for (d = a[n]; d <= (cnt >> 1); ++d)
        if (!(cnt % d)) dfs(d, cnt / d, a[n]);
    printf("%d", cnt);
}
2023/4/10 13:34
加载中...