题目链接: 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​,...,psi​​as 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 =1<<21;
typedef long long ll;int n,a[25],b[25],pre[25];
ll dp[N],cnt[N];void solve() {dp[0] = 0;ll res = 0;for(int i=1; i<=n; i++) {for(int j=0; j<n; j++) {for(int k=0; k<(1<<n); k++) {if(cnt[k]!=i-1 || ((k>>j)&1)==1 || (k&pre[j])!=pre[j])continue;if(k+(1<<j) >=(1<<n)) continue;if(dp[k]+1LL*a[j]*i+b[j] >= dp[k+(1<<j)]) {dp[k+(1<<j)] = dp[k]+a[j]*i+b[j];cnt[k+(1<<j)] = cnt[k]+1;res = max(res, dp[k+(1<<j)]);}}}}cout << res <<endl;
}int main ()
{//freopen("in.txt","r",stdin);scanf("%d", &n);for(int i=0; i<n; i++){int T;scanf("%d %d %d",&a[i], &b[i], &T);while (T--) {int k; scanf("%d",&k);pre[i] |= (1<<(k-1));}}solve();return 0;
}

转载于:https://www.cnblogs.com/Draymonder/p/9571492.html

ACM-ICPC 2018 南京赛区网络预赛 E AC Challenge 状压DP相关推荐

  1. ACM-ICPC 2018 南京赛区网络预赛 J AC Challenge (状压dp)

    题意 给你n道题,在你做第ii{i}道题的时候有p[j]p[j]{p[j]}个前置条件,当这些前置条件都满足的时候,我们可以得到a[j]∗t+b[j]a[j]∗t+b[j]a[j] * t + b[j ...

  2. ACM-ICPC 2018 南京赛区网络预赛 E.AC Challenge 状压dp

    题意: 给定n个作业,每个作业有两个值a,b, 第i天完成这个作业会得到value :i*a + b: 但是完成这个任务之前需要完成一些别的任务 思路: 乍一看像是搜索,但是似乎不太行(好像可以写过) ...

  3. ACM-ICPC 2018 南京赛区网络预赛 E. AC Challenge 状压dp

    Dlsj is competing in a contest with n(0<n≤20)n (0 < n \le 20)n(0<n≤20) problems. And he kno ...

  4. 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 ...

  5. ACM-ICPC 2018 南京赛区网络预赛 E. AC Challenge

    题解 题目大意 给你n个问题 要求每分钟解决一个问题 且不能中断 如果中断当前得分为最终得分 每个问题的得分为 解决时间*a[i] + b[i] 有的问题需要先完成某些问题才能做 使用状压DP 用二进 ...

  6. ACM-ICPC 2018 南京赛区网络预赛 E AC Challenge

    题目链接:https://nanti.jisuanke.com/t/30994 题意:有n道题,做第i道题首先得做Si道题(p1​,p2​,...,psi​​),做一道题需要一分钟,在t时刻完成第i道 ...

  7. ACM-ICPC 2018 南京赛区网络预赛 E. AC Challenge(状压dp)

    题目链接:https://nanti.jisuanke.com/t/30994 样例输入1 5 5 6 0 4 5 1 1 3 4 1 2 2 3 1 3 1 2 1 4 样例输出1 55 样例输入2 ...

  8. ACM-ICPC 2018 南京赛区网络预赛丨AC Challenge丨状压DP

    题意: 一个人做n道题目,每道题会收获ai*t+bi的分数,同时要休息一个单位的时间t.此外,还限制做题目i之前,要先完成si道题目{pi1,pi2,···,pisi}求最多获得多少分数. 思路: n ...

  9. ACM-ICPC 2018 南京赛区网络预赛

    轻轻松松也能拿到区域赛名额,CCPC真的好难 An Olympian Math Problem 问答 只看题面 54.76% 1000ms 65536K Alice, a student of gra ...

最新文章

  1. javascript优缺点_为什么要在JavaScript中使用静态类型? 优缺点
  2. 用计算机的英语造句process,process的用法总结大全
  3. mysql数据库oem_Oracle 11gR2学习之二(创建数据库及OEM管理篇)
  4. angular ajax get post 参数,AngularJS - $ http.post发送请求参数而不是JSON的任何方式?...
  5. Java中this的简单应用
  6. .NET开发人员如何开始使用ML.NET
  7. 计算机考研文章精选[转载]
  8. 微服务的通信协议:Restful,RPC(Dubbo、Motan、gRPC)
  9. mybatis plus使用in查询
  10. Golang在Linux环境下的POSIX风格socket编程
  11. Pentium的保护工作方式
  12. 棋牌游戏-c#实现批量修改文件后缀
  13. java poi 水印_poi excel如何设置水印透明度
  14. 【计算广告】浅谈广告归因
  15. iPhone 13,战略性“不香”!
  16. 设置Word文档密码的两种方式
  17. 【C语言:精准打击】scanf_s()函数与scanf()函数的相关解决方案
  18. Keil(MDK-ARM)系列教程(八)_在线调试(Ⅰ)
  19. 批量生成各尺寸的iOS图标
  20. python笑傲江湖_ensp模拟器上玩python编程自动化(入门)

热门文章

  1. java调用cmd命令执行mysql命令
  2. 深入了解jvm虚拟机
  3. 数学:确定性的丧失---第八章 不合逻辑的发展:天堂之门
  4. JAXB根据带继承关系的类生成soap请求的XML报文(互转)
  5. 《网络攻防》实验三:免杀原理与实践
  6. c语言标准化考试系统课程设计,c语言标准化考试系统课程设计
  7. 使用 satis 搭建一个私有的 Composer 包仓库 在我们的日常php开发中可能需要使用大量的composer包,大部份都可以直接使用,但在公司内部总有一小部份包是不能公开的,这时候我们就需
  8. Grakn Forces 2020 D E F
  9. NOIP simulation
  10. K-Means集群算法