【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;
}

最新文章

  1. No.021:Merge Two Sorted Lists
  2. Sharepoint client model 中出现Cannot invoke HTTP DAV request. There is a pending query 的解决办法
  3. Task示例,多线程
  4. Python Webk框架学习 Flask
  5. lr_convert_string_encoding()转码函数
  6. WCF中Service Configuration Editor的使用方法
  7. WCF 配置终结点并调用服务
  8. 敏捷开发的价值观(转自MBAlib)
  9. Mongodb与关系型数据库
  10. xcode语法高亮插件
  11. MySql 如何实现不同数据库同步【2个】
  12. Python 数据分析包:pandas 基础
  13. 锁和监视器之间的区别 – Java并发
  14. layer弹出层传值到父页面
  15. ES 18 - (底层原理) Elasticsearch写入索引数据的过程 以及优化写入过程
  16. listcard记录
  17. [Vue warn]: Cannot find element: #main
  18. Java基础语法 第4节 常见软件安装-Mysql和SQLyog
  19. OpenResty全功能Web应用服务器,打包了标准的 nginx 核心
  20. 2018-2019-2 网络对抗技术 20165219 Exp6 信息搜集与漏洞扫描

热门文章

  1. Object-c Associated Object
  2. PHP str_replace() 和str_ireplace()函数
  3. grpc编译错误解决
  4. PostgreSQL Replication之第四章 设置异步复制(4)
  5. PostgreSQL中流复制pg_basebackup做了什么
  6. js thousand separator and change td content
  7. S-Nim POJ - 2960 Nim + SG函数
  8. UVA-10200 Prime Time 素数(注意除法精度)
  9. MySQL好弱智的一个错误
  10. 【模板】2-SAT 问题(2-SAT)