'commit'
This commit is contained in:
36
TangDou/LanQiaoBei/LanQiaoBei13ShengSai_ZJ_II/4.cpp
Normal file
36
TangDou/LanQiaoBei/LanQiaoBei13ShengSai_ZJ_II/4.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user