You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
648 B
36 lines
648 B
#include <bits/stdc++.h>
|
|
/**
|
|
5 2
|
|
200 145 240 50 45
|
|
150 300
|
|
答案
|
|
4
|
|
*/
|
|
using namespace std;
|
|
int m, n;
|
|
const int N = 310;
|
|
int a[N], b[N];
|
|
int res;
|
|
void dfs(int u, int s) {
|
|
if (u == n + 1) {
|
|
res = max(res, s);
|
|
return;
|
|
}
|
|
|
|
dfs(u + 1, s);
|
|
|
|
for (int i = 1; i <= m; i++)
|
|
if (a[u] <= b[i]) {
|
|
b[i] -= a[u]; //回溯
|
|
dfs(u + 1, s + 1);
|
|
b[i] += a[u];
|
|
}
|
|
}
|
|
int main() {
|
|
cin >> n >> m;
|
|
for (int i = 1; i <= n; i++) cin >> a[i];
|
|
for (int i = 1; i <= m; i++) cin >> b[i];
|
|
dfs(1, 0);
|
|
printf("%d\n", res);
|
|
return 0;
|
|
} |