HOJ-10513 Allocation Scheme[简单DFS]
2012-07-20 09:06
295 查看
http://acm.hnu.cn/online/?action=problem&type=show&id=10513
注意一下输入,要以文件结束。
code:
Allocation Scheme |
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB |
Total submit users: 69, Accepted users: 64 |
Problem 10513 : No special judgement |
Problem description |
A manager of one company received a emergent project that needs to be completed in shortest time。With considering and analysing, the manager would divide the project into N independent tasks and that needs N employees to complete. Every ernployee can do any one of the N tasks, but the time is different. Please design a allocation scheme for the manager to make the task can be completed in shortest time. |
Input |
The number of the employees N begins with 0, so is the tasks number N. The time of every task done by every employee is stored in a two-dimensional array task_worker . For example: task_worker[i][j] means the time of task i completed by employee j. |
Output |
The first row show the shortest time to complete the project.(unit: hour) Output the situation of the allocation scheme. |
Sample Input |
10 11 12 11 9 11 11 9 10 13 11 12 12 10 11 10 13 9 9 14 9 10 10 11 10 10 9 11 12 11 10 7 10 10 10 8 |
Sample Output |
The shortest time is 54 hours Task 0 is distributed to employee 4 Task 1 is distributed to employee 1 Task 2 is distributed to employee 3 Task 3 is distributed to employee 0 Task 4 is distributed to employee 2 Task 5 is distributed to employee 5 |
Problem Source |
HNU Contest |
code:
#include <iostream> #include <iomanip> #include <fstream> #include <sstream> #include <algorithm> #include <string> #include <set> #include <utility> #include <queue> #include <stack> #include <list> #include <vector> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <ctype.h> using namespace std; int map[101][101]; char str[101]; int record[101]; int record1[101]; int vst[101]; int mintime; int n; char t[101]; void DFS(int cnt,int sum) { int i; if(cnt==n+1) { if(sum<mintime) { mintime=sum; for(i=0;i<=n;i++) record1[i]=record[i]; } return; } for(i=0;i<=n;i++) { if(!vst[i]) { vst[i]=1; record[cnt]=i; DFS(cnt+1,sum+map[cnt][i]); vst[i]=0; } } } int main() { int i,j; int temp; while(gets(str)) { memset(map,0,sizeof(map)); memset(record,0,sizeof(record)); n=0; temp=0; for(i=0;i<strlen(str);i++) { if(str[i]==' '&&str[i+1]!=' ') { map[0] /=10; n++; } else if(str[i]!=' ') { map[0] +=(int(str[i])-48); map[0] *=10; } else{ } } for(i=1;i<=n;i++) for(j=0;j<=n;j++) scanf("%d",&map[i][j]); cin>>t; mintime=9999999; for(i=0;i<=n;i++) { memset(vst,0,sizeof(vst)); memset(record,0,sizeof(record)); vst[i]=1; record[0]=i; DFS(1,map[0][i]); } printf("The shortest time is %d hours\n",mintime); for(i=0;i<=n;i++) printf("Task %d is distributed to employee %d\n",i,record1[i]); } return 0; }
相关文章推荐
- POJ 1111 Image Perimeters 简单DFS
- poj1111 hoj 1639 Image Perimeters 简单搜索
- hdu1016枚举递归-经典DFS-简单回溯入门
- HDU 1010题解这是一道简单的DFS加回溯题,看懂后就会对递归和回溯有较深刻的理解。
- POJ2386 Lake Counting简单dfs
- bzoj 1088 简单dfs
- POJ2386-简单BFS/DFS
- POJ 1321 棋盘问题 简单的DFS
- hdu Prime Ring Problem (java 简单DFS)
- hdu 题目1181 变形课 (简单DFS)
- poj - 2386 Lake Counting && hdoj -1241Oil Deposits (简单dfs)
- Red and Black(简单dfs)
- hdu - 1010 Tempter of the Bone (dfs+奇偶性剪枝) && hdu-1015 Safecracker(简单搜索)
- HDU1016 Prime Ring Problem DFS 简单题
- Hdu1312 Red and Black 【简单dfs】
- 简单dfs:UVA 260 Il Gioco dell'X
- Codeforces Beta Round #95 (Div. 2) D. Subway 【简单dfs】
- 暴力求解——UVA 572(简单的dfs)
- XCOM Enemy Unknown 简单的dfs() 枚举就行,不过有个用二进制压缩的没看懂
- (简单)搜索 HOJ 1030 Labyrinth