UVA10817--状态压缩DP
第一次做状态压缩dp。。没有思路。。看书看明白的,不过看完发现汝哥的做法多算了一些东西,完全可以省去不算。。
用两个集合,s1表示恰好有一个人教的科目,s2表示至少有两个人教的科目。d(i,s1,s2),表示考虑了前i个人时的最小花费,0-m-1必须全选上,m到m-n-1才有可能出现选或者不选的
决策,状态转移方程:d(i,s1,s2)=min{d(i+1,s1,s2),fee[i] + d(i+1,s1‘,s2’)},第一项表示不聘用,还是以现在的s1,s2进入第i+1个人,第二项表示聘用,并且更新状态。
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<cmath>
#include<sstream>
#include<queue>
#define INF 1000000000
using namespace std;
const int maxn = ; int s,m,n;
int fee[];
int st[];
int d[][<<][<<]; int dp(int i, int s1, int s2) {//学习啦。。。orz
if(i == m+n) return s2 == (<<s) - ? : INF;//递归边界
int& ans = d[i][s1][s2];
if(ans >= ) return ans;//曾经计算过 ans = INF;
if(i >= m) ans = dp(i+, s1, s2); int m1 = st[i] & s1;
s1 = st[i]^s1;
s2 |= m1;
ans = min(ans, fee[i] + dp(i+, s1, s2));//orz。。
return ans;
} int main()
{
//freopen("in","r",stdin);
string line;
while(getline(cin,line))//学习一下读入方式orz
{
stringstream ss(line);
ss>>s>>m>>n;
if(s == ) break;
// cout<<s<<m<<n;
for(int i = ; i < m+n; ++i)
{
getline(cin,line);
stringstream ss(line);
ss >> fee[i];//printf("***%d\n",fee[i]);
int x;
st[i] = ;
while(ss >> x) st[i]|=(<<(x-));//ss有个返回值?
}
memset(d,-,sizeof(d));//注意初始化!!
cout<<dp(,,)<<endl;//初始状态,从第0个人,s1 = 0,s2 = 0;
}
}
UVA10817--状态压缩DP的更多相关文章
- hoj2662 状态压缩dp
Pieces Assignment My Tags (Edit) Source : zhouguyue Time limit : 1 sec Memory limit : 64 M S ...
- POJ 3254 Corn Fields(状态压缩DP)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4739 Accepted: 2506 Descr ...
- [知识点]状态压缩DP
// 此博文为迁移而来,写于2015年7月15日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w6jf.html 1.前 ...
- HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP
题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...
- DP大作战—状态压缩dp
题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...
- 状态压缩dp问题
问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...
- BZOJ-1226 学校食堂Dining 状态压缩DP
1226: [SDOI2009]学校食堂Dining Time Limit: 10 Sec Memory Limit: 259 MB Submit: 588 Solved: 360 [Submit][ ...
- Marriage Ceremonies(状态压缩dp)
Marriage Ceremonies Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- HDU 1074 (状态压缩DP)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:有N个作业(N<=15),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ...
- HDU 4511 (AC自动机+状态压缩DP)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4511 题目大意:从1走到N,中间可以选择性经过某些点,比如1->N,或1->2-> ...
随机推荐
- C# 合成图片
教师节快到了,给那些年的老师拼个图 前端有脸.眉.眼.特征.气泡等多元素图片 后端将最后选中元素的ID,合成“脸谱” /// <summary> /// 合并图片 /// </sum ...
- Building bridges_hdu_4584(排序).java
Building bridges Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) ...
- [RxJS] Sharing Streams with Share
A stream will run with each new subscription added to it. This lesson shows the benefits of using sh ...
- [Redux] Extracting Container Components (FilterLink)
Learn how to avoid the boilerplate of passing the props down the intermediate components by introduc ...
- 【转】Difference between Point-To-Point and Publish/Subscribe JMS Messaging Models
Difference between Point-To-Point and Publish/Subscribe JMS Messaging Models Point-to-Point (PTP) ...
- android-用xml自定义背景(可自定义显示具体那一边)
常见的描边都是闭合的.四个边都有.如下: <?xml version="1.0" encoding="UTF-8"?> <layer-list ...
- SDK文件夹下内容介绍
Platform-Tools: 这是 adb, fastboot 等工具包.把解压出来的 platform-tools 文件夹放在 android sdk 根目录下,并把 adb所在的目录添加到系统 ...
- 作为java应届生,面试求职那点事
找工作两星期多了.心情不爽,写点记录打发时间. 嘘~~自己的破事: 刚毕业,也过了实习,本理所应当的留在公司转正.可是为了谈了两年的女朋友回家见面.一切都顺利进行,妈妈也开心给了一万见面礼,一切都以 ...
- DTO学习系列之AutoMapper(二)
本篇目录: Flattening-复杂到简单 Projection-简单到复杂 Configuration Validation-配置验证 Lists and Array-集合和数组 Nested m ...
- JAVA采用JDBC连接操作数据库详解
JDBC连接数据库概述 一.JDBC基础知识 JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供 ...