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.

45 lines
812 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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;
}