Files
python/TangDou/LanQiaoBei/LanQiaoBei13ShengSai_ZJ_II/4.cpp

36 lines
648 B
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#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;
}