您的位置:首页 > 其它

HOJ-10513 Allocation Scheme[简单DFS]

2012-07-20 09:06 295 查看
http://acm.hnu.cn/online/?action=problem&type=show&id=10513

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: