https://odzkskevi.qnssl.com/b506a3c20adad78678917d1ff4c9b953?v=1508327485

【题解】

dp[i][S1][S2]表示前i个教师选/不选已经决策完,当前有一个老师教的课程为S1,两个老师教的课程为S2,还需要的最小价值

答案为dp[0][0][0]

转移即可

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b)) inline void swap(int &a, int &b)
{
int tmp = a;a = b;b = tmp;
} inline void read(int &x)
{
x = ;char ch = getchar(), c = ch;
while(ch < '' || ch > '')c = ch, ch = getchar();
while(ch <= '' && ch >= '')x = x * + ch - '', ch = getchar();
if(c == '-')x = -x;
} const int INF = 0x3f3f3f3f;
const int MAXN = + ;
const int MAXM = + ;
const int MAXS = ; struct Edge
{
int u,v,nxt;
Edge(int _u, int _v, int _nxt){u = _u;v = _v;nxt = _nxt;}
Edge(){}
}edge[MAXN << ];
int head[MAXN], cnt; inline void insert(int a, int b)
{
edge[++cnt] = Edge(a,b,head[a]);
head[a] = cnt;
} int m,n,s,c[MAXN + MAXM],a[MAXN + MAXM],dp[MAXN + MAXM][ << MAXS][ << MAXS],ma;
std::string ch; int DP(int i, int s0, int s1, int s2)
{
if(i > n + m) return s2 == ma - ? : INF;
if(dp[i][s1][s2] >= )return dp[i][s1][s2];
dp[i][s1][s2] = INF;
if(i > m) dp[i][s1][s2] = DP(i + , s0, s1, s2);
int tmp1 = s0 & a[i], tmp2 = s1 & a[i];
dp[i][s1][s2] = min(dp[i][s1][s2], DP(i + , s0^tmp1, (s1 ^ tmp2) | tmp1, s2 | tmp2) + c[i]);
return dp[i][s1][s2];
} int main()
{
while(scanf("%d %d %d", &s, &m, &n) != EOF && n + m + s)
{
std::cin.get();
memset(dp, -, sizeof(dp));
memset(a, , sizeof(a));
int tmp;
for(register int i = ;i <= m + n;++ i)
{
getline(std::cin, ch);
std::stringstream cc(ch);
cc >> c[i];
a[i] = ;
while(cc >> tmp)
a[i] |= << (tmp - );
}
ma = << s;
printf("%d\n", DP(, ma - , , ));
}
return ;
}

UVA10817

Uva10817 Headmaster's Headache的更多相关文章

  1. UVA 10817 十一 Headmaster's Headache

    Headmaster's Headache Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Sub ...

  2. UVA 10817 Headmaster's Headache(DP +状态压缩)

    Headmaster's Headache he headmaster of Spring Field School is considering employing some new teacher ...

  3. 状压DP UVA 10817 Headmaster's Headache

    题目传送门 /* 题意:学校有在任的老师和应聘的老师,选择一些应聘老师,使得每门科目至少两个老师教,问最少花费多少 状压DP:一看到数据那么小,肯定是状压了.这个状态不好想,dp[s1][s2]表示s ...

  4. Headmaster's Headache UVA - 10817

    UVA-10817 ans[i][s1][s2]表示考虑前i个人时,有至少1人教的科目集合为s1,有至少2人教的科目集合为s2时的最少工资集合用一个数字表示,转换成二进制后从后面开始数第i位的状态(1 ...

  5. UVa 10817 (状压DP + 记忆化搜索) Headmaster's Headache

    题意: 一共有s(s ≤ 8)门课程,有m个在职教师,n个求职教师. 每个教师有各自的工资要求,还有他能教授的课程,可以是一门或者多门. 要求在职教师不能辞退,问如何录用应聘者,才能使得每门课只少有两 ...

  6. Headmaster's Headache

    题意: s门课程,现任老师有m个给出工资,和他们能教的课,现在有n个应聘的老师,给出费用和能教的课程标号,求使每门课都至少有两个老师教的最小花费 分析: n个老师选或不选有背包的特征,n很小想到用状压 ...

  7. UVa 10817 Headmaster's Headache (状压DP+记忆化搜索)

    题意:一共有s(s ≤ 8)门课程,有m个在职教师,n个求职教师.每个教师有各自的工资要求,还有他能教授的课程,可以是一门或者多门. 要求在职教师不能辞退,问如何录用应聘者,才能使得每门课只少有两个老 ...

  8. uva 10817 - Headmaster's Headache ( 状态压缩dp)

    本文出自   http://blog.csdn.net/shuangde800 题目链接: 点击打开链接 题目大意 某校有n个教师和m个求职者,已知每人的工资和能教的课程集合,要求支付最少的工资使得每 ...

  9. 【UVa】Headmaster's Headache(状压dp)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

随机推荐

  1. iOS7新特性-完美解决iOS7关于自定义导航条UIBarButtonItem偏移的问题

    前言: 本文由DevDiv社区@Vincent 原创,转载请注明出处! http://www.devdiv.com/iOS_iPhone-ios_ios_uibarbuttonitem_-thread ...

  2. LintCode_13 字符串查找

    题目 对于一个给定的 source 字符串和一个 target 字符串,你应该在 source 字符串中找出 target 字符串出现的第一个位置(从0开始).如果不存在,则返回 -1. 您在真实的面 ...

  3. 服务器迁移部署OmsWeb

    绑定 基本设置 高级设置

  4. 报错C1189 #error: "No Target Architecture"

    根本原因: 是因为单独包含了一些windows.h已经包含了的头文件如"fileapi.h","WinUser.h",但是却没有包含windows.h 或者先包 ...

  5. hibernate使用truncate清空表 截断表

    public void truncateTable(Session session, String tableNameInDb) { String sql = " truncate tabl ...

  6. 2019-5-21-C#-在-构造函数添加-CallerMemberName-会怎样

    title author date CreateTime categories C# 在 构造函数添加 CallerMemberName 会怎样 lindexi 2019-05-21 11:28:32 ...

  7. Selenium浏览器自动化测试使用(1)

    Selenium - 介绍 Selenium是一个开源的和便携式的自动化软件测试工具,用于测试Web应用程序有能力在不同的浏览器和操作系统运行.Selenium真的不是一个单一的工具,而是一套工具,帮 ...

  8. [编织消息框架][传输协议]sctp简单开发

    jdk1.7支持sctp协议,需要linux安装sctp支持库 测试代码 public class ServerSCTP { static int SERVER_PORT = 3456; static ...

  9. JavaSE_01_Exception类

    1.1 异常概念 指的是程序在执行过程中,出现的非正常的情况,最终会导致JVM的非正常停止. 在Java等面向对象的编程语言中,异常本身是一个类,产生异常就是创建异常对象并抛出了一个异常对象.Java ...

  10. Vue简单评星效果与单张图片上传

    <form class="" id="pj-frm"> <div class="assess-header"> &l ...