hdoj1373 Channel Allocation(极大团)

题意是有若干个接收器,给出每个接收器的相邻接收器。相邻的接收器不能使用同一信号频道。问所需要的信号频道数。

求该无向图的极大团。

 1 #include<iostream>
 2 #include<cstring>
 3 #include<string>
 4 #define maxn 30
 5 using namespace std;
 6 int stack[maxn],map[maxn][maxn];
 7 int n,cn,bestn;
 8 void dfs(int x){
 9     if (x>n){
10         bestn=max(cn,bestn);
11         return ;
12     }
13     int flag=1;
14     for (int i=0;i<cn;i++){
15         if (!map[stack[i]][x]){
16             flag=0;
17             break;
18         }
19     }
20     if (flag){
21         stack[cn++]=x;
22         dfs(x+1);
23         cn--;
24     }
25     if (cn+n-x>bestn){
26         dfs(x+1);
27     }
28 }
29 int main(){
30     string S;
31     while (cin >> n && n){
32         memset(map,0,sizeof(map));
33         for (int id=0;id<n;id++){
34             cin >> S;
35             int pre=S[0]-'A';
36             int len=S.length();
37             for (int i=2;i<len;i++){
38                 int res=S[i]-'A';
39                 map[pre][res]=map[res][pre]=1;
40             }
41            }
42         cn=bestn=0;
43         memset(stack,0,sizeof(stack));
44         dfs(0);
45         if (bestn==1) cout << "1 channel needed.\n";
46         else cout << bestn << " channels needed.\n";
47     }
48     return 0;
49 }

 

转载于:https://www.cnblogs.com/changer-qyz/p/8514233.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值