比赛 4043级NOIP2022欢乐赛8th 评测结果 AAATTTTTTTTTTTEETEEE
题目名称 Sleeping Cows 最终得分 15
用户昵称 HeSn 运行时间 12.900 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2022-11-21 19:54:30
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;
int n, a[110], b[110], vis[110], vis1[110], ans;
void dfs(int x) {
	if(x > n) {
		for(int i = 1; i <= n; i ++) {
			if(vis1[i]) {
				continue;
			}
			for(int j = 1; j <= n; j ++) {
				if(!vis[j] && b[j] >= a[i]) {
					return ;
				}
			}
		}
		ans ++;
		return ;
	}
	dfs(x + 1);
	for(int i = 1; i <= n; i ++) {
		if(!vis[i] && b[i] >= a[x]) {
			vis[i] = 1;
			vis1[x] = 1;
			dfs(x + 1);
			vis1[x] = 0;
			vis[i] = 0;
		}
	}
}
signed main() {
	freopen("usaco_20Dec_sleep.in", "r", stdin);
	freopen("usaco_20Dec_sleep.out", "w", stdout);
	cin >> n;
	for(int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	for(int i = 1; i <= n; i ++) {
		cin >> b[i];
	}
	sort(a + 1, a + n + 1);
	sort(b + 1, b + n + 1);
	dfs(1);
	cout << ans;
	return 0;
}