Atcoder190-c



题目链接:https://atcoder.jp/contests/abc190/tasks/abc190_c

排列树,数据比较少,暴力搜索即可

参考代码

#include <bits/stdc++.h> 
using namespace std;
#define int long long
const int K = 20,N = 110;
int n,m,k,ans = -1;
int p[K];
vector<pair<int,int>  > condi;
vector<pair<int,int> > pu;
int st[N];
void f(int idx){
	if(idx == k+1){
		memset(st,0,sizeof st);
		int tmp = 0;
		for(int i = 1; i <= k; i ++){
			if(p[i] == 0){
				st[pu[i-1].first] += 1;
			}else{
				st[pu[i-1].second] += 1;
			}
		}
		
		for(int i = 0; i < m; i++){
			if(st[condi[i].first] >= 1 && st[condi[i].second] >= 1){
				tmp++;
			}
		}
		ans = max(ans,tmp);
		return;
	}
	p[idx] = 1;
	f(idx + 1);
	p[idx] = 0;
	
	f(idx + 1);
}


signed main()
{
	#ifndef ONLINE_JUDGE
	freopen("tpl.txt","r",stdin) ;
#endif
	cin >> n >> m;
	
	for(int i = 0; i < m; i++){
		int a,b; cin >> a >> b;
		condi.push_back({a,b});
	}
	cin >> k;
	
	for(int i = 0; i < k; i++){
		int c,d; cin >> c >> d;
		pu.push_back({c,d});
	}
	f(1);
	cout << ans;
}
posted @ 2021-02-02 21:53  cainiao11024  阅读(98)  评论(0编辑  收藏  举报