HOJ-10513 Allocation Scheme[简单DFS]

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[N][N]. 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:

 1  #include <iostream>   

 2  #include <iomanip>   

 3  #include <fstream>   

 4  #include <sstream>   

 5  #include <algorithm>   

 6  #include <string>   

 7  #include <set>   

 8  #include <utility>   

 9  #include <queue>   

10  #include <stack>   

11  #include <list>   

12  #include <vector>   

13  #include <cstdio>   

14  #include <cstdlib>   

15  #include <cstring>   

16  #include <cmath>   

17  #include <ctime>   

18  #include <ctype.h> 

19  using namespace std;

20  

21  int map[101][101];

22  char str[101];

23  int record[101];

24  int record1[101];

25  int vst[101];

26  int mintime;

27  int n;

28  char t[101]; 

29  

30  void DFS(int cnt,int sum)

31  {

32      int i;

33      if(cnt==n+1)

34      {

35          if(sum<mintime)

36          {

37              mintime=sum;

38              for(i=0;i<=n;i++)

39                  record1[i]=record[i];

40          }

41          return;  

42     }

43     for(i=0;i<=n;i++)

44     {

45         if(!vst[i])

46         {

47             vst[i]=1;

48             record[cnt]=i; 

49             DFS(cnt+1,sum+map[cnt][i]);

50             vst[i]=0;

51         }

52     }

53  }

54  

55  int main()

56  {

57      int i,j;

58      int temp;

59      while(gets(str))

60      {

61          memset(map,0,sizeof(map));

62          memset(record,0,sizeof(record));

63          n=0;

64          temp=0;

65          for(i=0;i<strlen(str);i++)

66          {

67              if(str[i]==' '&&str[i+1]!=' ')

68              {

69                  map[0][n]/=10;

70                  n++;

71              }

72             else if(str[i]!=' ') 

73             {

74                 map[0][n]+=(int(str[i])-48);

75                 map[0][n]*=10;

76             } 

77             else{

78                 

79             }

80          }

81          for(i=1;i<=n;i++)

82              for(j=0;j<=n;j++)

83                  scanf("%d",&map[i][j]);

84          cin>>t; 

85        mintime=9999999;

86        for(i=0;i<=n;i++)

87        {

88            memset(vst,0,sizeof(vst));

89            memset(record,0,sizeof(record));

90              vst[i]=1;

91              record[0]=i;

92              DFS(1,map[0][i]);

93        }

94        printf("The shortest time is %d hours\n",mintime);

95        for(i=0;i<=n;i++)

96            printf("Task %d is distributed to employee %d\n",i,record1[i]);

97     }

98     return 0;

99  }

 

 

你可能感兴趣的:(location)