zoukankan      html  css  js  c++  java
  • 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.
    ";
    46         else cout << bestn << " channels needed.
    ";
    47     }
    48     return 0;
    49 }
  • 相关阅读:
    String与int转换,Java当中
    微信小程序首页的上一个页面栈和当前页面栈
    windows中用命令行实现http下载网络文件
    jmeter
    java
    java
    java请求python的x-www-form-urlencoded接口
    java
    getopts/getopt命令行参数处理
    failed command: READ FPDMA QUEUED
  • 原文地址:https://www.cnblogs.com/changer-qyz/p/8514233.html
Copyright © 2011-2022 走看看