int fac[50]{0}; int fac_cnt = 0; int max_num = 0; int min_num = 100; int bucket[51]{0}; // 统计每个长度的个数 int n; int sum = 0; int current_fac; int filled_bucket[50]{0}; int filled_bucket_cnt = 0;
booldfs(int l, int x, int idx) { // l是当次剩余的长度,x是次数,idx是上次搜到的索引 if (l == 0) { if (x == 2) // 剩一个一定可以拼 { returntrue; } else { returndfs(current_fac, x - 1, 0); } }
if (l < min_num) // 剩下的比最小长度还小 { returnfalse; }
for (int i = idx; i < filled_bucket_cnt; i++) { if (bucket[filled_bucket[i]] > 0) { bucket[filled_bucket[i]]--; if (dfs(l - filled_bucket[i], x, i)) { // cout << i << '\n'; bucket[filled_bucket[i]]++; returntrue; } elseif (l == current_fac || l == filled_bucket[i]) { bucket[filled_bucket[i]]++; returnfalse; }
bucket[filled_bucket[i]]++; } } returnfalse; }
boolcmp(int a, int b) { return a > b; }
intmain() { cin >> n; for (int i = 0; i < n; i++) { int ai; cin >> ai; max_num = max(ai, max_num); min_num = min(ai, min_num); sum += ai; if (bucket[ai] == 0) { filled_bucket[filled_bucket_cnt++] = ai; } bucket[ai]++; }