【Uva 10817】Headmaster's Headache
【Link】:
【Description】
一个学校,有s门课程(1<=s <=8),里面本身已经有m个老师了,然后还想招聘n个老师;
给出这m个老师和n个来应聘的老师的信息;
(c[i]->工资,以及他们能教哪几门课程);
原本的m个老师一定要继续保留下来;
问你在这个条件下,如何选取这n个老师中的一些人;
使得每门课都至少有两个人能教,且花费的总工资最少.
【Solution】
设f[i][j]表示前i个老师(不包括原有的m个老师),能教课程的状态为j的情况下最少需要花多少工资;
这里j由16位二进制组成
其中第2x位,表示第x门课程有没有一个老师教,第2x+1位表示第x门课程有没有两个老师教.
然后枚举前i个老师,枚举当前状态j;
然后从f[i][j]转移到f[i+1][temp]和f[i+1][j]
这里temp是选了第i+1个老师后j变成的状态;
f[i+1][temp]=min(f[i+1][temp],f[i][j]+c[i+1])
f[i+1][j]=min(f[i+1][j],f[i][j])
最后输出f[n][22∗s−1]
【NumberOf WA】
0
【Reviw】
选好了状态就不难写啦.
读到行末用gets.
【Code】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("D:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 100;
const int NN = 65536;
const int INF = 0x3f3f3f3f;
int s,m,n,temp1,temp2,two[20];
int c[N+10],sta[N+10],f[N+10][NN+10];
char temp[40];
int main(){
//Open();
//Close();
two[0] = 1;
rep1(i,1,19)
two[i] = two[i-1]*2;
while (~scanf("%d%d%d",&s,&m,&n) && s){
rep1(i,0,N)
rep1(j,0,NN)
f[i][j] = INF;
rep1(i,1,N) sta[i] = 0;
temp1 = 0,temp2 = 0;
rep1(i,1,m){
int x;
scanf("%d",&x);
temp2+=x;
gets(temp);
int len = strlen(temp);
rep1(j,0,len-1)
if (isdigit(temp[j])){
x = temp[j]-'0';
if (temp1 & two[2*(x-1)])
temp1 |= two[2*(x-1)+1];
else
temp1 |= two[2*(x-1)];
}
}
f[0][temp1] = temp2;
rep1(i,1,n){
scanf("%d",&c[i]);
gets(temp);
int len = strlen(temp);
rep1(j,0,len-1)
if (isdigit(temp[j])){
int x;
x = temp[j]-'0';
sta[i] |= two[2*(x-1)];
}
}
rep1(i,0,n-1)
rep1(j,0,two[2*s]-1)
if (f[i][j]<INF){
int temp3 = j;
rep1(k,0,s-1){
if (two[2*k]&sta[i+1]){
if (j&two[2*k])
temp3 |= two[2*k+1];
else
temp3 |= two[2*k];
}
}
f[i+1][j] = min(f[i+1][j],f[i][j]);
f[i+1][temp3] = min(f[i+1][temp3],f[i][j] + c[i+1]);
}
printf("%d\n",f[n][two[2*s]-1]);
}
return 0;
}
【Uva 10817】Headmaster's Headache的更多相关文章
- UVA 10817 十一 Headmaster's Headache
Headmaster's Headache Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Sub ...
- 【巧妙算法系列】【Uva 11464】 - Even Parity 偶数矩阵
偶数矩阵(Even Parity, UVa 11464) 给你一个n×n的01矩阵(每个元素非0即1),你的任务是把尽量少的0变成1,使得每个元素的上.下.左.右的元素(如果存在的话)之和均为偶数.比 ...
- 【贪心+中位数】【UVa 11300】 分金币
(解方程建模+中位数求最短累积位移) 分金币(Spreading the Wealth, UVa 11300) 圆桌旁坐着n个人,每人有一定数量的金币,金币总数能被n整除.每个人可以给他左右相邻的人一 ...
- 【UVa 10881】Piotr's Ants
Piotr's Ants Porsition:Uva 10881 白书P9 中文改编题:[T^T][FJUT]第二届新生赛真S题地震了 "One thing is for certain: ...
- 【UVa 116】Unidirectional TSP
[Link]:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- 【UVa 1347】Tour
[Link]:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- 【UVA 437】The Tower of Babylon(记忆化搜索写法)
[题目链接]:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- 【uva 1025】A Spy in the Metro
[题目链接]:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- 【Uva 11584】Partitioning by Palindromes
[Link]:https://cn.vjudge.net/contest/170078#problem/G [Description] 给你若干个只由小写字母组成的字符串; 问你,这个字符串,最少能由 ...
随机推荐
- iOS RegexKitLite 提取匹配的内容
使用RegexKitLite正则表达式需要以下工作: 1.RegexKitLite官方网址(内含使用教程):http://regexkit.sourceforge.net/RegexK ...
- WET Dilutes Performance Bottlenecks
WET Dilutes Performance Bottlenecks Kirk Pepperdine THE IMPORTANCE OF THE DRY PRINCIPLE (Don't Repea ...
- opecv2 MeanShift 使用均值漂移算法查找物体
#if !defined OFINDER #define OFINDER #include <opencv2\core\core.hpp> #include <opencv2\img ...
- poj--3620--Avoid The Lakes(dfs)
Avoid The Lakes Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Subm ...
- Java容器源码解析之——LinkedList
我们直接从源码来分析LinkedList的结构: public class LinkedList<E> extends AbstractSequentialList<E> im ...
- Kali linux 2016.2(Rolling)里Metasploit的口令猜测与嗅探
不多说,直接上干货! 对于发现的系统与文件管理类网络服务,比如Telnet.SSH.FTP等,可以进行弱口令的猜测,以及对明文传输口令的嗅探,从而尝试获取直接通过这些服务进入目标网络的通道. 对于SS ...
- CodeForcesEducationalRound40-D Fight Against Traffic 最短路
题目链接:http://codeforces.com/contest/954/problem/D 题意 给出n个顶点,m条边,一个起点编号s,一个终点编号t 现准备在这n个顶点中多加一条边,使得st之 ...
- Generational GC (Part one )
目录 什么是分代垃圾回收 对象对的年龄 新生代对象和老年对象 Ungar的分带垃圾回收 堆的结构 记录集 写入屏障 对象的结构 分配 新生代GC 幸存空间沾满了怎么办? 老年代GC 优缺点 吞吐量得到 ...
- hdu 6363 bookshelf
题解讲的很清楚了,直接看代码就懂了 题解:http://bestcoder.hdu.edu.cn/blog/2018-multi-university-training-contest-6-solut ...
- Node实现简单的注册时后端的MVC模型架构
实现一个简单的注册界面后端MVC模型架构 第一步:在生成的express框架的app.js中添加一个路由,代码如下:var api = require('./routes/api'); app.use ...