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 ...
随机推荐
- BUAA软工第一次作业-热身
第一次作业-热身 项目 内容 这个作业属于哪个课程 2020春季计算机学院软件工程(罗杰 任健) (北京航空航天大学 - 计算机学院) 这个作业的要求在哪里 第一次作业-热身作业(阅读) 我在这个课程 ...
- 【剑指Offer面试编程题】题目1517:链表中倒数第k个结点--九度OJ
题目描述: 输入一个链表,输出该链表中倒数第k个结点. (hint: 请务必使用链表.) 输入: 输入可能包含多个测试样例,输入以EOF结束. 对于每个测试案例,输入的第一行为两个整数n和k(0< ...
- thinkphp5.1 源码阅读
传送地址:https://github.com/cshaptx4869/tp5.1-code-read 包含: 自动加载 容器 配置文件 钩子 门面
- Linux --xrandr command
Source: https://www.x.org/archive/current/doc/man/man1/xrandr.1.xhtml https://blog.csdn.net/syh_486_ ...
- nth-of-type()的用法
同样的标签选择其中一个,就用nth-of-type() <img src="http://cms-bucket.nosdn.127.net/2018/10/16/ad8698e497e ...
- java学习-初级入门-面向对象③-类与对象-类与对象的定义和使用1
今天学习类与对象.先大致解释一下类与对象的含义. 对象:object 有物体这一概念,一切皆对象(物体),对象由静态的属性和动态的行为组成. 比如说水杯: 水杯的静态属性:材质,容量,质量,颜色 动态 ...
- Celery的常用知识
什么是Clelery Celery是一个简单.灵活且可靠的,处理大量消息的分布式系统.专注于实时处理的异步任务队列.同时也支持任务调度. Celery的架构由三部分组成,消息中间件(message ...
- Day2-O-Coloring a Tree CodeForces-902B
You are given a rooted tree with n vertices. The vertices are numbered from 1 to n, the root is the ...
- Core Data 基本数据操作 增删改查 排序
所有操作都基于Core Data框架相关 API,工程需要添加CoreData.framework支持 1.增 NSEntityDescription insertNewObjectForEntit ...
- 树莓派开启VNC远程桌面
分类: Raspberry Pi Linux2013-03-12 10:18 4288人阅读 评论(1) 收藏 举报 目录(?)[+] 1.安装VNC sudo apt-get install ...