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 ...
随机推荐
- 九度oj 1521 二叉树的镜像
原题链接:http://ac.jobdu.com/problem.php?pid=1521 水题,如下.. #include<algorithm> #include<iostream ...
- Java检测文件是否UTF8编码
介绍UTF-8编码规则 UTF-8 编码字符理论上可以最多到 6 个字节长, 然而 16 位 BMP 字符最多只用到 3 字节长. Bigendian UCS-4 字节串的排列顺序是预定的. 字节 0 ...
- sql server 查询数据库所有的表名+字段
SELECT * FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='Account' SELECT (case when a.colorder= ...
- iOS学习之C语言指针
访问数据的两种方式: 1.直接访问: 2.间接访问:先找到内存地址,根据地址访问存储单元.(内存地址 被称为指针) 定义指针变量: 类型修饰符 *指针变量名 = NULL; NULL表示空指针,相当 ...
- SQL Server数据库学习笔记-设计表时应该考虑的因素
设计数据库其实就是设计数据库中的表.到底要注意些什么才能够设计好一个数据库呢?一个宗旨,8个建议. 一个宗旨“尽量少的表,每个表中尽量少的列,合理的表结构”. 8个建议: 第一个,首先要考虑的是咱们这 ...
- js jquery 判断IE有效方法
jquery1.9以前 $.browser.msie jquery1.9更高版本 $.browser.msie = /msie/.test(navigator.userAgent.toLowerCas ...
- 第2章 变量和基本类型 附3---底层const和顶层const
和英文版的对: As we’ve seen, a pointer is an object that can point to a different object. As a result,we c ...
- VC++程序中加入自定义声音(PlaySound函数用法)
VC++编程中,我们可以为自己的程序加入音乐,比如当我们按下一个按钮时或者启动程序时,播放一小段音乐. 该功能用到函数: BOOL PlaySound(LPCSTR pszSound, HMODULE ...
- JPA学习---第九节:JPA中的一对多双向关联与级联操作
一.一对多双向关联与级联操作 1.创建项目,配置文件代码如下: <?xml version="1.0" encoding="UTF-8"?> < ...
- Analyzer使用第二Y轴,以及同一分析图不同量值使用不同的图形样式
Analyzer的建立分析图后,图中有两个量值,希望能显示成不同的图形样式,如一个是柱图.一个是线图. 1.设置显示多个量值: 3.设置显示出图例,即表明图中量值内容的说明: 2.右键图例中要修改为不 ...