POJ 1129 Channel Allocation DFS 回溯】的更多相关文章

Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15546   Accepted: 7871 Description When a radio station is broadcasting over a very large area, repeaters are used to retransmit the signal so that every receiver has a s…
题目:http://poj.org/problem?id=1129 题意:求最小m,使平面图能染成m色,相邻两块不同色由四色定理可知顶点最多需要4种颜色即可.我们于是从1开始试到3即可. #include <iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<stack> #include<queue> #include<iomanip&…
POJ 1129 Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14191   Accepted: 7229 Description When a radio station is broadcasting over a very large area, repeaters are used to retransmit the signal so that every receive…
Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13173   Accepted: 6737 Description When a radio station is broadcasting over a very large area, repeaters are used to retransmit the signal so that every receiver has a s…
题目: http://poj.org/problem?id=1129 开始没读懂题,看discuss的做法,都是循环枚举的,很麻烦.然后我就决定dfs,调试了半天终于0ms A了. #include <stdio.h> #include <string.h> ][], vis[][]; int n, ans; void calc() { ; ; i < ; i++) { ; j < n; j++) { if(vis[j][i]) { cnt++; break; } }…
题意: N个中继站,相邻的中继站频道不得相同,问最少需要几个频道. 输入输出: Sample Input 2 A: B: 4 A:BC B:ACD C:ABD D:BC 4 A:BCD B:ACD C:ABD D:ABC 0 Sample Output 1 channel needed. 3 channels needed. 4 channels needed. 题意抽象+思路: 一张有N个点的无向图,对每个点进行染色,相邻的点颜色不得一致,最少需多少种颜色.DFS即可. 代码: <span s…
http://poj.org/problem?id=1129 import java.util.*; import java.math.*; public class Main { public static boolean flag=false; public static int ans=0; public static void main(String []args) { Scanner cin=new Scanner(System.in); int n; String str; whil…
http://poj.org/problem?id=1154 #include<iostream> using namespace std; ]={},s,r,sum=,s1=; ][]; ][]={-,,,,,-,,}; void dfs(int a,int b) { int a1,b1; if(s1>sum) sum=s1; //更新最大数值 ;i<;i++) { a1=a+dir[i][]; //用bb数组记录访问过的字母 b1=b+dir[i][]; &&a…
题目大意建模: 一个有N个节点的无向图,要求对每个节点进行染色,使得相邻两个节点颜色都不同,问最少需要多少种颜色? 那么题目就变成了一个经典的图的染色问题 例如:N=7 A:BCDEFG B:ACDEFG C:ABD D:ABCE E:ABDF F:ABEG G:ABF 画成图就是: 首先考虑四色定理:任何一张地图只用四种颜色就能使具有共同边界的国家着上不同的颜色 judge(int x,int y)枚举判断x的邻接点中是否着色y颜色的 1.正向考虑dfs(int num,int color)从…
题目链接:http://poj.org/problem?id=1321 题意:中文题目,就不多说了...... 思路: 解题方法挺多,刚开始想的是先从N行中选择出来含有“#”的K行,再在这K行中放置K个棋子,就好了.时间复杂度为O( C(n, k)  *  k! ),真实写的时候其实用了2N * k!,勉强也过了.后面又想到可以先从第一个出现的“#”开始搜,搜完之后直接跳到下一行继续,就不用第一次做那么麻烦了. 代码: (1) #include <iostream> #include <…