染色问题:相邻不能染同一种颜色

最少需要的颜色的数量=最大团点的数量

#include<bits/stdc++.h>
using namespace std; #define N 27 int n;
int mp[N][N];
int ans;
int alt[N][N];
int Max[N]; bool dfs(int cur,int tot)//cur是s1集合的个数
{
if(==cur)
{
if(tot>ans)
{
ans=tot;return true;
}
return false;
} for(int i=;i<cur;i++)
{
if( tot+cur-i<=ans )return false;
int u=alt[tot][i];
if( Max[u]+tot<=ans )return false;
int next=;
for(int j=i+;j<cur;j++)
if(mp[u][ alt[tot][j] ])alt[tot+][next++]=alt[tot][j];
if(dfs(next,tot+)) return ;
}
return ;
} int maxclique(void)
{
ans=;
memset(Max,,sizeof(Max));
for(int i=n-;i>=;i--)
{
int cur=;
for(int j=i+;j<n;j++)if(mp[i][j])alt[][cur++]=j;//1为s1集合
dfs(cur,);
Max[i]=ans;
}
return ans;
} int main()
{ char s[]; while(scanf("%d",&n),n)
{
memset(mp,,sizeof (mp));
for(int i=;i<n;i++)
{
scanf("%s",s);
for(int j=;s[j];j++)
mp[i][ s[j]-'A' ]=mp[ s[j]-'A' ][i]=;
}
int ans=maxclique();
if(ans==) printf("1 channel needed.\n");
else printf("%d channels needed.\n", ans);
}
return ;
}

Channel Allocation HDU1373的更多相关文章

  1. poj1129 Channel Allocation

    Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14361   Accepted: 73 ...

  2. 迭代加深搜索 POJ 1129 Channel Allocation

    POJ 1129 Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14191   Acc ...

  3. Channel Allocation

    Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13231 Accepted: 6774 D ...

  4. poj1129 Channel Allocation(染色问题)

    题目链接:poj1129 Channel Allocation 题意:要求相邻中继器必须使用不同的频道,求需要使用的频道的最少数目. 题解:就是求图的色数,这里采用求图的色数的近似有效算法——顺序着色 ...

  5. Channel Allocation (poj 1129 dfs)

    Language: Default Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12 ...

  6. Channel Allocation(DFS)

    Channel Allocation Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) ...

  7. POJ 1129 Channel Allocation(DFS)

    Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13173   Accepted: 67 ...

  8. 快速切题 poj1129 Channel Allocation

    Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12334   Accepted: 63 ...

  9. POJ 1129 Channel Allocation DFS 回溯

    Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15546   Accepted: 78 ...

随机推荐

  1. 洛谷 P2862 [USACO06JAN]把牛Corral the Cows 解题报告

    P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being fi ...

  2. IntelliJ IDEA远程调试运行中的JAVA程序/项目

    一.IntelliJ IDEA配置 1.添加一个运行配置(remote项) 2.打开remote项配置对话框 3.远程jvm参数配置提示 4.远程调试的ip地址和端口号,ip就是java项目所在机器i ...

  3. 在c语言中嵌入汇编语句,对于我来说相当难。

    今天早上在csdn论坛上看到一个帖子http://topic.csdn.net/u/20120917/14/82f42e17-977a-4824-95bd-7b79db15d283.html:“C语言 ...

  4. 螺旋队列和hiho1525逃离迷宫3

    我是真调不出错误了! hiho1525逃离迷宫3 #include <stdio.h> #include <stdlib.h> #include <math.h> ...

  5. webService与分布式与微服务与SOA的关系

    SOA:是面向服务体系架构. webservice是SOA的一种实现技术.webservice基于两种协议:soap和rest协议.现在常用的是rest协议. web service (web 服务) ...

  6. Python常用模块-随机数模块(random)

    Python常用模块-随机数模块(random) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.常用方法举例 #!/usr/bin/env python #_*_coding: ...

  7. Spring RedisTemplate操作-通道操作(10)

    @Autowired @Resource(name = "redisTemplate") private RedisTemplate<String, String> r ...

  8. Mybatis 使用 mapper 接口规范的 一对一, 一对多,多对多映射

    首先的 是 最原始的 pojo 类来 做简单映射 简单 pojo 映射: <mapper namespace="com.ghc.dao.UserDao"> <se ...

  9. MySql数据库表的查询操作

    http://www.cnblogs.com/whgk/p/6149009.html 优化:http://www.ihref.com/read-16422.html MYSQL常用的几种连接查询方法

  10. XMPP用户登录

    CHENYILONG Blog XMPP用户登录 技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http://weibo.com/luohanchenyilon ...