ABC002D 派閥题解

题意

给定一个 n(1≤n≤12)n(1 \leq n \leq 12)n(1n12) 个点 mmm 条边的图(无重边自环,图不保证联通),求最多能选出几个点使这些点两两之间全部有边连接。

思路

鉴于 nnn 范围很小,考虑到所有情况数(即每次挑选的人方案数) 共有 2n≤40962^n \leq 40962n4096 种情况,最后两两之间判断 n2n^2n2,总共复杂度 2n×n22^n \times n^22n×n2,可以接受。因为 nnn 范围,我们甚至可以使用邻接矩阵存储图的信息。

代码

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,x,y;
bool c[15][15];
int a[15],ans = 0;
void dfs(int now,int cnt) {
	if(now == n + 1) {
		for(int i = 1;i <= cnt;i++) {
			for(int j = 1;j < i;j++) {
				if(!c[a[i]][a[j]]) return;
			}
		}
		ans = max(ans,cnt);
		return;
	}
	dfs(now + 1,cnt);
	a[++cnt] = now,dfs(now + 1,cnt),a[cnt--] = 0;
}
signed main() {
	scanf("%lld %lld",&n,&m);
	for(int i = 1;i <= m;i++) scanf("%lld %lld",&x,&y),c[x][y] = c[y][x] = 1;
	dfs(1,0);
	printf("%lld\n",ans); 
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值