'commit'
This commit is contained in:
45
TangDou/KaoShi/比身高.cpp
Normal file
45
TangDou/KaoShi/比身高.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
/**
|
||||
3 0
|
||||
165 175 163
|
||||
155 165 157
|
||||
答案:4
|
||||
*/
|
||||
|
||||
int n, k;
|
||||
|
||||
const int N = 110;
|
||||
int a[N], b[N];
|
||||
int cnt;
|
||||
int st[N];
|
||||
|
||||
void dfs(int u, int s) {
|
||||
if (u == n + 1) {
|
||||
cnt++;
|
||||
return;
|
||||
}
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (!st[i]) {
|
||||
if (a[u] >= b[i]) {
|
||||
st[i] = 1;
|
||||
dfs(u + 1, s);
|
||||
st[i] = 0;
|
||||
}
|
||||
|
||||
if (a[u] < b[i] && s < k) {
|
||||
st[i] = 1;
|
||||
dfs(u + 1, s + 1);
|
||||
st[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int main() {
|
||||
cin >> n >> k;
|
||||
for (int i = 1; i <= n; i++) cin >> a[i];
|
||||
for (int i = 1; i <= n; i++) cin >> b[i];
|
||||
dfs(1, 0);
|
||||
printf("%d\n", cnt);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user