ACM-Work Assignment
输入
第一行有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的更多相关文章
- ACM学习历程—HDU 5289 Assignment(线段树 || RMQ || 单调队列)
Problem Description Tom owns a company and he is the boss. There are n staffs which are numbered fro ...
- [论文笔记] 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 ...
- 2015 Multi-University Training Contest 1 - 1002 Assignment
Assignment Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Mean: 给你一个数列和一个k,求连续区间的极值之 ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- hdu 2853 Assignment KM算法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2853 Last year a terrible earthquake attacked Sichuan ...
- 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 ...
- HDU 5289 Assignment rmq
Assignment 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Description Tom owns a company and h ...
- 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个工程,每个需要某 ...
- HDU 5289 Assignment (ST算法区间最值+二分)
题目链接:pid=5289">http://acm.hdu.edu.cn/showproblem.php?pid=5289 题面: Assignment Time Limit: 400 ...
- HDU 5289 Assignment [优先队列 贪心]
HDU 5289 - Assignment http://acm.hdu.edu.cn/showproblem.php?pid=5289 Tom owns a company and he is th ...
随机推荐
- 常用WinAPI函数整理------------转载
常用WinAPI函数整理原创 玩撕你 发布于2019-09-04 20:06:55 阅读数 101 收藏展开 之前的博客写了很多关于Windows编程的内容,在Windows环境下的黑客必须熟练掌握底 ...
- css实现单行居中,两行居左
居中需要用到 text-align:center,居左是默认值也就是text-align:left.要让两者结合起来需要多一个标签. <h2><p>单行居中,多行居左</ ...
- 【剑指Offer面试编程题】题目1512:用两个栈实现队列--九度OJ
题目描述: 用两个栈来实现一个队列,完成队列的Push和Pop操作. 队列中的元素为int类型. 输入: 每个输入文件包含一个测试样例. 对于每个测试样例,第一行输入一个n(1<=n<=1 ...
- 新闻网大数据实时分析可视化系统项目——7、Kafka分布式集群部署
Kafka是由LinkedIn开发的一个分布式的消息系统,使用Scala编写,它以可水平扩展和高吞吐率而被广泛使用.目前越来越多的开源分布式处理系统如Cloudera.Apache Storm.Spa ...
- Javascript调用本地数据库
window.location.href = urls; // 本窗口打开下载 window.open(urls, '_blank'); // 新开窗口下载 (1)new ActiveXObject( ...
- 如何给Sqlite添加复合主键
如果是想两个字段组成一个复合主键的话可以如下.SQL code sqlite> create table t2 ( ...> id1 int , ...> id2 int, ...& ...
- DICOM的Worklist服务
看 DICOM 标准有一段时间了,前面几篇也介绍了一下 DIMSE-C 消息服务,具体参看Dicom 学习笔记-Dicom 消息服务(DIMSE-C/DIMSE-N),本文就介绍一下 DICOM 标准 ...
- 深入理解python(二)python基础知识之数据结构
数据结构 Python中的内置数据结构(Built-in Data Structure):列表list.元组tuple.字典dict.集合set,这里只着重说前三个 >>> d=di ...
- SpringBoot 静态资源的配置
springboot默认的静态资源目录: classpath:/static classpath:/public classpath:/resources classpath:/META-INF/re ...
- 题解 UVA10298 【Power Strings】
此题我写的是后缀数组SA解法,如果不会后缀数组的可以跳过本篇blog了. 参考文献:罗穗骞 2009集训队后缀数组论文 前记 最近学后缀数组,肝了不少题,也分出了后缀数组的几个题型,看这题没有后缀数组 ...