1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| using namespace std; using namespace FAST_IO; const ll mod = 1e9 + 7; const int INF = 0x3f3f3f3f; const ll INF_LL = 0x3f3f3f3f3f3f3f3f; const double eps = 1e-5; const int maxn = 1e2 + 10; const int maxm = 1e5 + 10; int t, n, m, k; int a[maxn]; int cnt; bool vis[maxn]; bool cmp(int x, int y) { return x > y; }
bool dfs(int step, int curLen, int maxLen, int num) { if (num >= cnt) return true; if (curLen == maxLen) return dfs(0, 0, maxLen, num + 1); int fail = 0; for (int i = step; i < n; i++) { if (!vis[i] && a[i] != fail && (curLen + a[i] <= maxLen)) { vis[i] = true; if (dfs(i + 1, curLen + a[i], maxLen, num)) { return true; } vis[i] = false; fail = a[i]; if (curLen == 0 || curLen + a[i] == maxLen) return false; } } return false; } int main() {
#ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif while (scanf("%d", &n) && n) { int sum = 0; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); sum += a[i]; } sort(a, a + n, cmp); for (int i = a[0]; i <= sum; i++) { if (sum % i) continue; cnt = sum / i; memset(vis, 0, sizeof(vis)); if (dfs(0, 0, i, 0)) { printf("%d\n", i); break; } } } return 0; }
|