uva 10817
Problem D: Headmaster's Headache |
Time limit: 2 seconds |
The headmaster of Spring Field School is considering employing some new teachers for certain subjects. There are a number of teachers applying for the posts. Each teacher is able to teach one or more subjects. The headmaster wants to select applicants so that each subject is taught by at least two teachers, and the overall cost is minimized.
Input
The input consists of several test cases. The format of each of them is explained below:
The first line contains three positive integers S, M andN. S (≤ 8) is the number of subjects, M (≤ 20) is the number of serving teachers, and N (≤ 100) is the number of applicants.
Each of the following M lines describes a serving teacher. It first gives the cost of employing him/her (10000 ≤ C ≤ 50000), followed by a list of subjects that he/she can teach. The subjects are numbered from 1 to S. You must keep on employing all of them.After that there are N lines, giving the details of the applicants in the same format.
Input is terminated by a null case where S = 0. This case should not be processed.
Output
For each test case, give the minimum cost to employ the teachers under the constraints.
Sample Input
2 2 2
10000 1
20000 2
30000 1 2
40000 1 2
0 0 0
Sample Output
60000
状态dp
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int MAX_N = ;
const int INF = ;
int S, M, N;
int ns1 = , ns2 = ;
int s[MAX_N], prize[MAX_N];
int dp[ << ][ << ]; void solve() {
dp[ns1][ns2] = prize[];
dp[ns2][ns1] = prize[];
for(int i = ; i <= N; ++i) {
for(int s1 = ( << S) - ; s1 >= ; --s1) {
for(int s2 = ( << S) - ; s2 >= ; --s2) {
if(dp[s1][s2] != INF) {
dp[s1 | s[i]][s1 & s[i] | s2] =
min(dp[s1 | s[i]][s1 & s[i] | s2]
, dp[s1][s2] + prize[i]); dp[s2 & s[i] | s1][s2 | s[i]] =
min(dp[s2 & s[i] | s1][s2 | s[i]]
, dp[s1][s2] + prize[i]);
}
}
}
}
} int main()
{
//freopen("sw.in","r",stdin);
while(~scanf("%d%d%d", &S, &M, &N) && (S + M + N)) {
ns1 = ; ns2 = ;
for(int i = ; i < ( << S); ++i)
for(int j = ; j < ( << S); ++j) dp[i][j] = INF;
memset(prize, , sizeof(prize));
memset(s, , sizeof(s)); for(int i = ; i <= M; ++i) {
int ch, v;
char c;
scanf("%d%d%c",&v, &ch, &c);
prize[] += v;
ns2 |= ns1 & ( << (ch - ));
ns1 |= << (ch - ); while(c != '\n') {
scanf("%d%c", &ch, &c);
ns2 |= ns1 & ( << (ch - ));
ns1 |= << (ch - );
} } for(int i = ; i <= N; ++i) {
int ch;
char c;
scanf("%d%d%c", &prize[i], &ch, &c);
s[i] |= << (ch - );
while(c != '\n') {
scanf("%d%c", &ch, &c);
s[i] |= << (ch - );
}
} solve();
printf("%d\n", dp[( << S) - ][( << S) - ]);
}
return ;
}
uva 10817的更多相关文章
- UVA 10817 十一 Headmaster's Headache
Headmaster's Headache Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Sub ...
- uva 10817(数位dp)
uva 10817(数位dp) 某校有m个教师和n个求职者,需讲授s个课程(1<=s<=8, 1<=m<=20, 1<=n<=100).已知每人的工资c(10000 ...
- 状压DP UVA 10817 Headmaster's Headache
题目传送门 /* 题意:学校有在任的老师和应聘的老师,选择一些应聘老师,使得每门科目至少两个老师教,问最少花费多少 状压DP:一看到数据那么小,肯定是状压了.这个状态不好想,dp[s1][s2]表示s ...
- UVa 10817 - Headmaster's Headache(状压DP)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 10817 - Headmaster's Headache(三进制状压dp)
题目:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=20&pag ...
- uva 10817(状压dp)
题意:就是有个学校要招老师.要让没门课至少有两个老师可以上.每个样样例先输入三个数字课程数量s,已经在任的老师数量,和应聘的老师数量.已经在任的一定要聘请. 思路是参考了刘汝佳书上的,关键如何状压. ...
- UVa 10817 (状压DP + 记忆化搜索) Headmaster's Headache
题意: 一共有s(s ≤ 8)门课程,有m个在职教师,n个求职教师. 每个教师有各自的工资要求,还有他能教授的课程,可以是一门或者多门. 要求在职教师不能辞退,问如何录用应聘者,才能使得每门课只少有两 ...
- UVa 10817 Headmaster's Headache (状压DP+记忆化搜索)
题意:一共有s(s ≤ 8)门课程,有m个在职教师,n个求职教师.每个教师有各自的工资要求,还有他能教授的课程,可以是一门或者多门. 要求在职教师不能辞退,问如何录用应聘者,才能使得每门课只少有两个老 ...
- UVA 10817 Headmaster's Headache(DP +状态压缩)
Headmaster's Headache he headmaster of Spring Field School is considering employing some new teacher ...
随机推荐
- Unity Scripting Tutorials 要点记录
(搬运自我在SegmentFault的博客) 这几天通过Unity官网的Unity Scripting Tutorials的视频学习Unity脚本,观看的过程中做了记录.现在,整理了一下笔记,供自己以 ...
- ios view的frame和bounds之区别(位置和大小)
前言: 学习ios开发有一段时间了,项目也做了两个了,今天看视频,突然发现view的frame和bound两个属性,发现bound怎么也想不明白,好像饶你了死胡同里,经过一番尝试和思考,终于弄明白bo ...
- 值类型和引用类型(C#基础知识复习)
一.值类型和引用类型 二.值类型的赋值和相等 三.引用类型的赋值和同一
- "大账户"时代
当要下载某文件时,哪怕是免积分,也需要登陆账户才能下载. 当要浏览某论坛时,只有注册账户,才可以浏览帖子. 当要网购商品时,必须注册账户,还要有众多宝宝平台,才可以实现交易. 当要团购时,必须先 ...
- lucene .NET 搜索图片 功能实现
关于搜索部分 1想建立索引.构建jpg图片解析器,在索引时将jpg图片的exif信息及其文本信息如名称,存放路径,大小,日期等等加入索引!具体实现代码如下: public void BulidInde ...
- Python: 迭代器与生成器小结
迭代器与生成器的区别: 1. 迭代器由Class对象创建. 生成器由包含yield表达的Function对象或者Generator Expression创建. 2. 迭代器的原理: (1)由Itera ...
- Your First ASP.NET 5 Application on a Mac
Your First ASP.NET 5 Application on a Mac By Daniel Roth, Steve Smith, Rick Anderson ASP.NET 5 is cr ...
- iOS进阶学习-数据处理之文件读写
一.沙盒机制 1.什么是沙盒? 每一个iOS应用程序都会为自己创建一个文件系统目录(文件夹),这个独立.封闭.安全的空间,叫做沙盒. 2.沙盒机制(SandBox) 沙盒是一种安全体系. 它规定了应用 ...
- 点击TableView中某行进入下一级界面(Swift)
TableView这个控件在iOS的开发中非常的常见,他可以较好的展示一个层级结构.这里主要介绍,在点击某个条目的时候,如何进行跳转的下一个界面.以下是官方的关于这个跳转如何去实现,和如何去传递数据的 ...
- 四、VMware Tools 安装 与 问题
解决VMware Tools无法安装的问题 虚拟机上装win2kgho版的系统,安装VMware Tools时,遇到“VMware Tools installation cannot be start ...