【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 中client和server的 Web Service 网络通信 (1)
当你打开你手机上新浪微博应用或者知乎应用是.你是否会去想这些显示在手机上的图片和数据时从哪里来的?又是通过如何的方法实现的?好.那么接下来就介绍是如何实现的.过程又是怎么样的. 当我们浏览着 ...
- Thinkphp 无法使用->order() 排序的两种解决的方法!
使用ThinkPHP,却发现无法使用->order($order)来排序. $order = " info.date2 desc "; 非常遗憾的是这样写结果order却变成 ...
- sass04 嵌套、继承、占位符
demo1.scss body{ //选择器嵌套 background-color:lightgray; header{ background-color:lightgreen; } footer{ ...
- 基于机器学习的web异常检测——基于HMM的状态序列建模,将原始数据转化为状态机表示,然后求解概率判断异常与否
基于机器学习的web异常检测 from: https://jaq.alibaba.com/community/art/show?articleid=746 Web防火墙是信息安全的第一道防线.随着网络 ...
- Struts2标签库整理【完整】
转自:https://blog.csdn.net/chen_zw/article/details/8161230 Struts2标签库提供了主题.模板支持,极大地简化了视图页面的编写,而且,str ...
- Android 代码中使用Color工具类 parseColor
方式一: arg1.setBackgroundColor(Color.parseColor("#87CEFA")); 方式二: arg1.setBackgroundColor(ge ...
- python import windows文件路经
import sys sys.path.append("E:\\python\\workspacepython\\PY001\\src\\testpy01") import str ...
- UVa 12661 Funny Car Racing【 dijkstra 】
题意:给出n个点,m条路,每条路用5个整数表示u,v,a,b,t u表示这条路的起点,v表示终点,a表示打开时间,b表示关闭时间,t表示通过这条道路需要的时间 看的紫书,因为边权不再仅仅是路上的时间, ...
- webService接口发布失败问题
今天在原有工程上新增加了个webService接口的服务类,但是总提示 axis2 出错 File "/axis2-web/listSingleService.jsp" not f ...
- Hello World基于.net framework中CLR的执行
static void Main(string[] args) { Console.WriteLine("Hello,World!"); Console.WriteLine(&qu ...