这个可以状态压缩,用二进制表示,每一位表示第几个选不选
然后就枚举两个子集,合并找最小的组数
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<iostream>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int
N= 1<<17;
int n,m,k,f[N];
bool map[20][20];
int tot;
int main()
{
scanf("%d%d%d",&n,&m,&k);
for(int i=1,x,y;i<=m;i++)
{
scanf("%d%d",&x,&y);
--x,--y;
map[x][y]=map[y][x]=1;
}
memset(f,127,sizeof(f));
for(int i=0;i<(1<<n);i++)
{
tot=0;
for(int j=0;j<n;j++)
for(int kk=j;kk<n;kk++)
if(map[j][kk]&&((1<<j)&i)&&((1<<kk)&i))
tot++;
if(tot<=k)
f[i]=1;
for(int j=i;j;j=(j-1)&i)
f[i]=min(f[i],f[j]+f[i^j]);
}
cout<<f[(1<<n)-1];
return 0;
}
最后
以上就是辛勤八宝粥最近收集整理的关于prison的全部内容,更多相关prison内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复