标签:existing sort 包含 hid print preview title main header
#include <bits/stdc++.h>
using namespace std;
const int maxn = 20;
bool jl;
int c[maxn], f[maxn];
int n, w;
bool cmp(int a, int b) { return a > b; }
void find(int x, int j) {
if (x == n + 1) {
jl = 1;
return;
}
for (int i = 1; i <= j; i++)
if (f[i] + c[x] <= w) {
f[i] += c[x];
find(x + 1, j);
f[i] -= c[x];
if (jl)
return;
}
}
int main() {
cin >> n >> w;
int sum = 0;
for (int i = 1; i <= n; i++) {
cin >> c[i];
sum += c[i];
}
sort(c + 1, c + n + 1, cmp);
for (int i = sum / w; i <= n; i++) {
find(1, i);
if (jl) {
printf("%d\n", i);
return 0;
}
}
return 0;
}
标签:existing sort 包含 hid print preview title main header
原文地址:https://www.cnblogs.com/hellohhy/p/13226583.html