题目描述:Work Assignment
 
设有n件工作分配给n个人。将工作i 分配给第j 个人所需的费用为Cij。试设计一个算法,为每一个人都分配1 件不同的工作,并使总费用达到最小。 设计一个算法,对于给定的工作费用,计算最佳工作分配方案,使总费用达到最小。

输入

第一行有1 个正整数n (1≤n≤30)。接下来的n行,每行n个数,表示工作费用。

输出

的最小总费用。

样例输入

3
10 2 3
2 3 4
3 4 5

样例输出

9

解题思路:按照工作任务DFS搜索即可。注意要标记每个人只能做一项工作。

 // Work Assignment.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h" #include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; const int MAX = ;
int n,ans, map[MAX][MAX],vis[MAX]; //第index项工作,现在前index-1项工作总费用
void DFS(int index, int sum)
{
//cout << "index:" << index << "\tsum:" << sum << "\tans:" << ans << endl;
if (index >= n)
{
ans = min(ans, sum);
return;
}
if (sum > ans) return; //分配给第i个人
for (int i = ; i < n; i++)
{
if (!vis[i])
{
vis[i] = ;
DFS(index + , sum + map[index][i]);
vis[i] = ;
} } } int main()
{
while (cin>>n && n)
{
for (int i = ; i < n;i++)
for (int j = ; j < n; j++)
cin >> map[i][j]; ans = 0x3f3f3f3f;
memset(vis, , sizeof(vis)); for (int i = ; i < n; i++)
{
vis[i] = ;
DFS(, map[][i]);
vis[i] = ;
} cout << ans << endl; } return ;
}

ACM-Work Assignment的更多相关文章

  1. ACM学习历程—HDU 5289 Assignment(线段树 || RMQ || 单调队列)

    Problem Description Tom owns a company and he is the boss. There are n staffs which are numbered fro ...

  2. [论文笔记] Methodologies for Data Quality Assessment and Improvement (ACM Comput.Surv, 2009) (1)

    Carlo Batini, Cinzia Cappiello, Chiara Francalanci, and Andrea Maurino. 2009. Methodologies for data ...

  3. 2015 Multi-University Training Contest 1 - 1002 Assignment

    Assignment Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Mean: 给你一个数列和一个k,求连续区间的极值之 ...

  4. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  5. hdu 2853 Assignment KM算法

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2853 Last year a terrible earthquake attacked Sichuan ...

  6. HDU 5874 Friends and Enemies 【构造】 (2016 ACM/ICPC Asia Regional Dalian Online)

    Friends and Enemies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  7. HDU 5289 Assignment rmq

    Assignment 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Description Tom owns a company and h ...

  8. hdu6006 Engineer Assignment 状态dp 定义dp[i][s]表示前i个工程状态为s可以执行的最大工程数。s表示前i个工人选走了s状态的工程师。

    /** 题目:hdu6006 Engineer Assignment 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6006 题意:已知n个工程,每个需要某 ...

  9. HDU 5289 Assignment (ST算法区间最值+二分)

    题目链接:pid=5289">http://acm.hdu.edu.cn/showproblem.php?pid=5289 题面: Assignment Time Limit: 400 ...

  10. HDU 5289 Assignment [优先队列 贪心]

    HDU 5289 - Assignment http://acm.hdu.edu.cn/showproblem.php?pid=5289 Tom owns a company and he is th ...

随机推荐

  1. URL构成及各个协议默认端口

    url的构成:一般来说,http请求都会和URL地址有关,对于url来说一般由下面5个部分构成 .协议:通常就是第一个冒号之前的内容常见协议:http,https(http+ssl),ftp,ssh, ...

  2. 大部分政府网站U-mail存在直接拿shell漏洞

    大部分网站政府网站U-mail存在直接拿shell漏洞加入webmail/userapply.php?execadd=333&DomainID=111直接爆出物理地址 然后将 aa' unio ...

  3. jgrid异步数据加载

    参考:https://blog.csdn.net/hurryjiang/article/details/7077725

  4. scrollBy 与 scrollTop的区别

    scrollTo是相对于初始位置 scrollBy是相对于上次移动的最后位置

  5. Django 3.0的新功能

    谷歌翻译的,我修正并且添加了一些内容.凑合看吧. MariaDB的支持 Django现在正式支持MariaDB 10.1和更高版本.有关更多详细信息,请参见MariaDB注释. ASGI支持 Djan ...

  6. 「NOIP2011」观光公交

    传送门 Luogu 解题思路 有点麻烦,幸好 \(O(n^2)\) 能过... 贪心地想一想,我们如果要用加速器,肯定是要选择车上人数最多的时段加速. 但是我们就会面临这样的情况: 加速了,带来了增益 ...

  7. IOS 3种内省方法

    IOS提供了3种内省方法 isKindOfClass 检查当前实例是否为某类及其子类 UIView *b = [UIView new]; //... id a = b; if ([a isMember ...

  8. POI 2001 Goldmine 线段树 扫描线

    题目链接 http://www.acm.cs.ecnu.edu.cn/problem.php?problemid=1350 http://main.edu.pl/en/archive/oi/8/kop ...

  9. python中判断素数的函数

    来看这一种判断素数(质数)的函数: form math import sart def is_prime(n): if n==1: return False for i in range(2, int ...

  10. JuJu团队1月7号工作汇报

    JuJu团队1月7号工作汇报 JuJu 周六周日放假,所以空了两天~   Scrum 团队成员 今日工作 剩余任务 困难 飞飞 完成data process readme部分 实现三维Dense 无 ...