要求:现有6项工作(0,1...5表示),现至多安排6位工程师去完成任务,每位工程师最多只能安排一项工作,而某项工作至多被安排一个工程师,而且保证工程师都不能空闲着,问可安排的方案数。
输入:
第一行:工程师个数n
接下来n行,每行表示工程师可胜任工作(如“01”表示胜任工作0,工作1)。
test case:
6
012345
012345
012345
012345
012345
012345
输出:
可能方案数。
test case:720
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int status[6];//status for the jobs(the max number is 6)
int dfs(const vector<string> &workers,int i) {
if (i == workers.size()) {
return 1;
}
int result = 0;
for (int j = 0; j < workers[i].size(); j++) {
if (status[workers[i][j] - '0']==1) {
status[workers[i][j] - '0'] = 0;
result += dfs(workers,i + 1);
status[workers[i][j] - '0'] = 1;
}
}
return result;
}
int main() {
vector<string> workers;
int n;
int result;
cin >> n;
for (int i = 0; i < n; i++) {
string x;
cin >> x;
workers.push_back(x);
}
for (int i = 0; i < 6; i++) status[i] = 1;//set the jobs status(1 means undoned,0 means doned)
result = dfs(workers,0);
cout << result << endl;
return 0;
}