poj 1129 DFS 无剪枝就可AC
2009-09-29 12:03
363 查看
这道题似乎也没什么剪枝可写,没有细想。
就是DFS。
还是,写代码的过程中牢牢记住DFS的思想即可。
代码如下:
就是DFS。
还是,写代码的过程中牢牢记住DFS的思想即可。
代码如下:
#include <iostream> #include <string> using namespace std; int rep[26][27],channelChosen[26]; bool check(int curRep,int curCha,int amount) { for (int j = 1;j <= rep[curRep][0];j++) { if(channelChosen[curRep]==channelChosen[rep[curRep][j]-1]) return false; } return true; } int DFS(int curRepeater,int curChannel,int num) { if(curRepeater>=num) return curChannel; for (int i = 1;i <= curChannel;i++) { channelChosen[curRepeater]=i; if(check(curRepeater,curChannel,num)) { return DFS(curRepeater+1,curChannel,num); } else continue; } channelChosen[curRepeater]=curChannel+1; return DFS(curRepeater+1,curChannel+1,num); } int main() { int numOfRepeaters; while (cin>>numOfRepeaters&&numOfRepeaters!=0) { string str; for (int i = 0;i < numOfRepeaters;i++) { cin>>str; int j = 1; string::iterator it = str.begin()+2; for (;it != str.end();it++) { rep[i][j++] = *it-'A'+1; } rep[i][0] = j-1; } int result = DFS(0,1,numOfRepeaters); string res = (result==1)?" channel needed.":" channels needed."; cout<<result<<res<<endl; } }
相关文章推荐
- Poj 1129 Channel Allocation(Dfs剪枝)
- hdoj--1010 ---Tempter of the Bone (dfs + 一些剪枝(擦边AC了), 居然又犯了老毛病, 我没有用奇偶性剪枝)
- poj 1011 sticks(木棒) (dfs+剪枝)
- POJ 1129 Channel Allocation DFS搜索 着色问题
- poj 1190 生日蛋糕(dfs 剪枝)
- poj 1129(DFS+四色定理)
- poj 1129 dfs
- poj 3373 Changing Digits(打表 + dfs + 剪枝 )
- poj 1129(dfs+图的四色定理)
- POJ 3172 Scales (dfs剪枝,dp超时)
- poj 1699 Best Sequence (搜索技巧 剪枝 dfs)
- poj 1011 dfs剪枝
- 【POJ】Square(DFS + 剪枝)
- POJ 2531 dfs回溯(小剪枝)
- POJ 2362 HDOJ 1518 Square DFS剪枝
- POJ 1010 STAMPS (DFS + 剪枝)
- [POJ 1011] Sticks DFS神剪枝
- POJ-1190-生日蛋糕-DFS(深搜)-枚举-多重剪枝
- POJ 生日蛋糕(DFS 巧妙剪枝)
- poj 1564 Sum It Up | zoj 1711 | hdu 1548 (dfs + 剪枝 or 判重)