网易互联网算法组笔试题一:为工程师分配工作

要求:现有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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值