Channel Allocation(POJ 1129)
来源:互联网 发布:库里职业生涯数据统计 编辑:程序博客网 时间:2024/06/09 20:40
题解:dfs(ps:这道题特别要注意输出格式 如果结果为1 使用channel,结果>1, 使用channels)
#include<iostream>#include<algorithm>#include<string.h>using namespace std;struct Node{ int c[30]; int num;}node[30];int board[30][30];int n;int nMin;void solve(int step,int sPos){ if(step==n){ if(sPos+1<nMin){ nMin=sPos+1; } return; } int i,j; for(i=0;i<=sPos;i++){ for(j=0;j<node[i].num;j++){ int pos=node[i].c[j]; if(board[step][pos]) break; } if(j==node[i].num){ node[i].c[j]=step; node[i].num++; solve(step+1,sPos); node[i].c[j]=0; node[i].num--; } } node[sPos+1].c[0]=step; node[sPos+1].num=1; solve(step+1,sPos+1); node[sPos+1].num=0; //extra code}int main(){ char ch; int src,target; while(cin>>n,n){ nMin=n; memset(board,0,sizeof(board)); cin.get(); for(int i=0;i<n;i++){ ch=cin.get(); src=ch-'A'; cin.get(); //absort : while(1){ ch=cin.get(); if(ch=='\n') break; target=ch-'A'; board[src][target]=1; } } node[0].c[0]=0; node[0].num=1; solve(1,0); //1 channel needed. if(nMin==1){ cout<<"1 channel needed."<<endl; }else{ cout<<nMin<<" channels needed."<<endl; } } return 0;}
0 0
- Channel Allocation(POJ 1129)
- poj 1129 Channel Allocation
- poj 1129 Channel Allocation
- poj 1129 Channel Allocation
- poj 1129Channel Allocation
- poj 1129 Channel Allocation
- poj 1129 Channel Allocation
- POJ 1129 Channel Allocation
- POJ 1129 Channel Allocation
- POJ 1129 Channel Allocation
- POJ 1129 Channel Allocation
- POJ 1129 Channel Allocation
- poj 1129 Channel Allocation
- POJ 1129 Channel Allocation
- Channel Allocation(poj 1129 )
- poj 1129 Channel Allocation
- POJ 1129--Channel Allocation
- poj 1129 Channel Allocation
- switchsharp升级版switchyomega试用
- Ubuntu下对只读文件的修改
- 容器的作用
- Hive中添加自定义UDF,UDAF,UDTF等函数jar文件的三种方式
- annotation-driven,annotation-config,component-scan的区别与作用
- Channel Allocation(POJ 1129)
- Majority Element
- HDU 4004
- CI项目配置xampp三部曲
- 解决ubuntu下 Non-keyword arg after keyword arg 的问题
- 推挽(Push-Pull) vs 开漏(Open-Drain)
- STL内存问题
- vector内存问题
- Android4.0窗口机制和创建过程分析