ACM-ICPC 2018 南京赛区网络预赛 E AC Challenge 状压DP
题目链接: https://nanti.jisuanke.com/t/30994
Dlsj is competing in a contest with n (0 < n \le 20)n(0<n≤20) problems. And he knows the answer of all of these problems.
However, he can submit ii-th problem if and only if he has submitted (and passed, of course) s_isi problems, the p_{i, 1}pi,1-th, p_{i, 2}pi,2-th, ......, p_{i, s_i}pi,si-th problem before.(0 < p_{i, j} \le n,0 < j \le s_i,0 < i \le n)(0<pi,j≤n,0<j≤si,0<i≤n) After the submit of a problem, he has to wait for one minute, or cooling down time to submit another problem. As soon as the cooling down phase ended, he will submit his solution (and get "Accepted" of course) for the next problem he selected to solve or he will say that the contest is too easy and leave the arena.
"I wonder if I can leave the contest arena when the problems are too easy for me."
"No problem."
—— CCF NOI Problem set
If he submits and passes the ii-th problem on tt-th minute(or the tt-th problem he solve is problem ii), he can get t \times a_i + b_it×ai+bi points. (|a_i|, |b_i| \le 10^9)(∣ai∣,∣bi∣≤109).
Your task is to calculate the maximum number of points he can get in the contest.
Input
The first line of input contains an integer, nn, which is the number of problems.
Then follows nn lines, the ii-th line contains s_i + 3si+3 integers, a_i,b_i,s_i,p_1,p_2,...,p_{s_i}ai,bi,si,p1,p2,...,psias described in the description above.
Output
Output one line with one integer, the maximum number of points he can get in the contest.
Hint
In the first sample.
On the first minute, Dlsj submitted the first problem, and get 1 \times 5 + 6 = 111×5+6=11 points.
On the second minute, Dlsj submitted the second problem, and get 2 \times 4 + 5 = 132×4+5=13 points.
On the third minute, Dlsj submitted the third problem, and get 3 \times 3 + 4 = 133×3+4=13 points.
On the forth minute, Dlsj submitted the forth problem, and get 4 \times 2 + 3 = 114×2+3=11 points.
On the fifth minute, Dlsj submitted the fifth problem, and get 5 \times 1 + 2 = 75×1+2=7 points.
So he can get 11+13+13+11+7=5511+13+13+11+7=55 points in total.
In the second sample, you should note that he doesn't have to solve all the problems.
样例输入1复制
5
5 6 0
4 5 1 1
3 4 1 2
2 3 1 3
1 2 1 4
样例输出1复制
55
样例输入2复制
1
-100 0 0
样例输出2复制
0
给n个问题,然后每个问题 给出a,b,s 分别表示 第i个解决这个题,就给 (a*i+b) 的收益,s表示有 s个前置问题,必须回答出来 s个前置问题 才能解决这个问题
之前没有写过状压DP, 但是了解过旅行商问题,所以,感觉这个题目暴力莽,就能过了
dp[state] 中 state按照每个2进制位,如果为1,代表这个题被解决,所以,dp[state] 表示 相应位为1的题目都被解决的 最大收益(因为每个题解决的顺序不同,所以可能有不同的收益,但是我们 状态表示的是最大收益)
然后我们可以用 pre[i] 表示想要解决第 i 个问题,需要解决的问题的(二进制为1)集合
接着我们就可以DP了
用cnt[state] 表示 state这个状态之前已经解决多少个问题了
对于第 i 次
对于 第 j 个问题
对于 每个状态k
如果状态k
如果 已经解决 i-1个问题 && 状态 k 没解决第j个问题 && 状态k 已经解决了第j个问题的 前置问题
分别对应 cnt[k] == i-1 && ((k>>j)&1)==0 && (k&pre[j]) ==pre[j]
那么 state = k+(1<<j) ,这个状态 dp[state] 就可以更新成 第i次解决 j题的收益+dp[k]
但是 这里我们这里还是过不了问题 , 还要保证一个条件 即 k+(1<<j) < (1<<n) 必须可以更新的状态 小于 (1<<n),超过的状态 无用,会得出错误的结果
#include<bits/stdc++.h>
using namespace std; const int N =<<;
typedef long long ll; int n,a[],b[],pre[];
ll dp[N],cnt[N]; void solve() {
dp[] = ;
ll res = ;
for(int i=; i<=n; i++) {
for(int j=; j<n; j++) {
for(int k=; k<(<<n); k++) {
if(cnt[k]!=i- || ((k>>j)&)== || (k&pre[j])!=pre[j])continue;
if(k+(<<j) >=(<<n)) continue;
if(dp[k]+1LL*a[j]*i+b[j] >= dp[k+(<<j)]) {
dp[k+(<<j)] = dp[k]+a[j]*i+b[j];
cnt[k+(<<j)] = cnt[k]+;
res = max(res, dp[k+(<<j)]);
}
}
}
}
cout << res <<endl;
} int main ()
{
//freopen("in.txt","r",stdin);
scanf("%d", &n);
for(int i=; i<n; i++)
{
int T;
scanf("%d %d %d",&a[i], &b[i], &T);
while (T--) {
int k; scanf("%d",&k);
pre[i] |= (<<(k-));
}
}
solve();
return ;
}
ACM-ICPC 2018 南京赛区网络预赛 E AC Challenge 状压DP的更多相关文章
- ACM-ICPC 2018 南京赛区网络预赛 E. AC Challenge (状态压缩DP)
Dlsj is competing in a contest with n (0 < n \le 20)n(0<n≤20) problems. And he knows the answe ...
- ACM-ICPC 2018 南京赛区网络预赛 E AC Challenge(状压dp)
https://nanti.jisuanke.com/t/30994 题意 给你n个题目,对于每个题目,在做这个题目之前,规定了必须先做哪几个题目,第t个做的题目i得分是t×ai+bi问最终的最大得分 ...
- ACM-ICPC 2018 南京赛区网络预赛 J.sum
A square-free integer is an integer which is indivisible by any square number except 11. For example ...
- ACM-ICPC 2018 南京赛区网络预赛 E题
ACM-ICPC 2018 南京赛区网络预赛 E题 题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest wi ...
- ACM-ICPC 2018 南京赛区网络预赛B
题目链接:https://nanti.jisuanke.com/t/30991 Feeling hungry, a cute hamster decides to order some take-aw ...
- 计蒜客 30999.Sum-筛无平方因数的数 (ACM-ICPC 2018 南京赛区网络预赛 J)
J. Sum 26.87% 1000ms 512000K A square-free integer is an integer which is indivisible by any squar ...
- 计蒜客 30996.Lpl and Energy-saving Lamps-线段树(区间满足条件最靠左的值) (ACM-ICPC 2018 南京赛区网络预赛 G)
G. Lpl and Energy-saving Lamps 42.07% 1000ms 65536K During tea-drinking, princess, amongst other t ...
- 计蒜客 30990.An Olympian Math Problem-数学公式题 (ACM-ICPC 2018 南京赛区网络预赛 A)
A. An Olympian Math Problem 54.28% 1000ms 65536K Alice, a student of grade 66, is thinking about a ...
- ACM-ICPC 2018 南京赛区网络预赛 B. The writing on the wall
题目链接:https://nanti.jisuanke.com/t/30991 2000ms 262144K Feeling hungry, a cute hamster decides to o ...
随机推荐
- 洛谷 P4697 Balloons [CEOI2011] 单调栈/dp (待补充qwq)
正解:单调栈/dp 解题报告: 先放个传送门qwq 话说这题是放在了dp的题单里呢?但是听说好像用单调栈就可以做掉所以我就落实下单调栈的解法好了qwq (umm主要如果dp做好像是要斜率优化凸壳维护双 ...
- (3.5)mysql基础深入——mysqld_safe脚本功能及流程
(3.5)mysql基础深入——mysqld_safe脚本功能及流程 目录 1.mysqld_safe过程总结 2.mysql_safe启动的好处 3.mysqld_safe 参数 4.mysqld_ ...
- dedecms如何调用当前栏目的子栏目及子栏目文章
前面ytkah谈到了 dedecms调用当前栏目的子栏目怎么操作,有的朋友会问如果再增加一个调用子栏目文章的需求,即调用当前栏目的子栏目及子栏目文章,这个有办法实现吗?这时就要涉及到另外两个标签的调用 ...
- hibernate中cascade和inverse
原文:http://blog.sina.com.cn/s/blog_7b9edd020100racc.html 这两个属性都用于一多对或者多对多的关系中. 而inverse特别是用于双向关系,在单向关 ...
- SqlServer--bat批处理执行sql语句1-osql
首先需要知道,此处使用的批处理命令是osql ,如果安装了SqlServer,目录类似: D:\Program Files\Microsoft SQL Server\100\Tools\Binn 脚本 ...
- 【剑指offer】包含min函数的栈
一.题目: 定义栈的数据结构,请在该类型中实现一个能够得到栈中所含最小元素的min函数. 二.思路: 无,Z(zhi)Z(zhang)式操作. 三.代码:
- [py]django表单不清空实现的2种方法
参考 参考: django实现内容不清空2种方法 django form的作用 1.生成html标签 2.验证输入内容 form生成表单 zhuji/forms.py - 实例化表单 - 定制form ...
- [adt]python实现栈-体验数据结构
经常使用py的一些数据结构,如list,及list的一些方法. 还有hash表等. 各类数据结构方法用的很6,然而不知道是底层是怎么实现的. 基于此,就开始研究一下py实现一些数据结构, 以便于对计算 ...
- 浅谈远程登录时,ssh的加密原理
SSH:Secure Shell,是一种网络安全协议,主要用于登录远程计算机的加密过程. 登录方式主要有两种: 1.基于用户密码的登录方式: 加密原理: 当服务器知道用户请求登录时,服务器会把 ...
- svn 常见问题记录
One or more files are in a conflicted state 情景:A组员新增文件并提交,B组员更新出现如下图情况. 解决方案:直接拷贝到B组员工作区.