Dlsj is competing in a contest with 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) si​ problems, the p1,p2,...pi,si​​-th problem before (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 i-th problem on t-th minute(or the t-th problem he solve is problem i), he can get t × ai ​+ bi​ points. (∣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 n, which is the number of problems.

Then follows nn lines, the i-th line contains si ​+ 3 integers ai​,bi​,si​,p1​,p2​,...,pi ​​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 × 5 + 6 = 11 points.

On the second minute, Dlsj submitted the second problem, and get 2 × 4 + 5 = 13points.

On the third minute, Dlsj submitted the third problem, and get 3 × 3 + 4 = 13 points.

On the forth minute, Dlsj submitted the forth problem, and get 4 × 2 + 3 = 11 points.

On the fifth minute, Dlsj submitted the fifth problem, and get 5 × 1 + 2 = 7 points.

So he can get 11 + 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

Hint

状态压缩记忆化dp

#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <map>
#include <algorithm>
#include <queue>
#include <set>
#include <cmath>
#include <sstream>
#include <stack>
#include <fstream>
#include <ctime>
#pragma warning(disable:4996);
#define mem(sx,sy) memset(sx,sy,sizeof(sx))
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-8;
const double PI = acos(-1.0);
const ll llINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
using namespace std;
//#define pa pair<int, int>
//const int maxn = 1000005;
//const int mod = 1e9 + 7;int n;
int a[25], b[25];
vector<int> pre[25];
int dp[22][1 << 20];
int vis[22];
bool judge(int x, int state) {if (!vis[x]) {int flag = 0;for (int i = 0; i < pre[x].size(); i++) {if ((state & (1 << pre[x][i])) == 0) {flag = 1; break;}}if (flag)return 0;return 1;}return 0;
}
int dfs(int t, int now) {if (dp[t][now] != -1) return dp[t][now];int ret = 0;for (int i = 1; i <= n; i++) {int curget = (t + 1) * a[i] + b[i];if (judge(i, now)) {vis[i] = 1;ret = max(ret, dfs(t + 1, now | (1 << i)) + curget);vis[i] = 0;}}dp[t][now] = ret;return ret;
}
int main() {while (~scanf("%d", &n)) {mem(dp, -1);mem(vis, 0);int s;for (int i = 1, s; i <= n; i++) {pre[i].clear();scanf("%d%d%d", &a[i], &b[i], &s);for (int j = 1, temp; j <= s; j++) {scanf("%d", &temp);pre[i].push_back(temp);}}int ans = dfs(0, 0);printf("%d\n", ans);}
}

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

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

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

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

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

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

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

  5. 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& ...

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

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

  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 南京赛区网络预赛 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 ...

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

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

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

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

最新文章

  1. 基于机器学习的捡球机器人设计与实现(探索)第1篇——树莓派系统的安装与配置(20190106)
  2. 安装指定版本的minikube
  3. Qt 程序打包发布总结
  4. Install VMware tools 解决(物理主机WIN7X64和VM下的REHAT LINUX AS4共享文件)
  5. 2017/05/11读性能测试书籍后感
  6. MS SQL入门基础:查看与修改索引
  7. SQL Server中的筛选后的统计信息和CE模型变化
  8. REST API 的安全认证,我放弃OAuth 2.0 ,选择 JWT 令牌
  9. Android 资源和国际化
  10. 标准cpci接口定义_cpci接口定义精简
  11. 不同时区时间换算_世界时区划分时差在线查询计算_时间换算器
  12. Hungry for your love 真爱无限
  13. php 在文本域中添加qq表情 createelement,仿微信在对话框文字中插入Emoji表情包
  14. CoinCola可盈可乐研究院2月报 | 加密货币集体上涨
  15. 轰动全球,一个月7级博客大V是如何炼成的!
  16. USB电路EMC设计标准电路详解
  17. c语言字符统计2sdut,山东理工大学SDUT - ACM OJ 题: Python代码 及分析
  18. python图片保存_Python中读取,显示,保存图片的方法
  19. 云师大计算机考研考什么,云南师范大学研究生院,云师大考研复试好难啊。
  20. 对对碰 代码 android,iOS分段选择器、旅行App、标度尺、对对碰小游戏、自定义相册等源码...

热门文章

  1. AES review
  2. idea测试API接口
  3. matlab计算地转流程序,geostrophy 用于海洋科学中计算地球流的一系列matlab程序 联合开发网 - pudn.com...
  4. 阿里云服务器搭建环境部署项目
  5. 异鲁米诺标记/多环芳烃半抗原载聚苯乙烯微球固载N-羟基邻苯二甲酰亚胺的制备反应
  6. 全心全意的服务,让转行的我能够成功斩获自己心仪的offer——享学课堂
  7. 【选品】Shopee虾皮马来西亚和印尼站点分析
  8. Git忽略文件及文件夹
  9. 《数值分析(原书第2版)》—— 2.4 PA=LU分解
  10. [Debug]modelsim simulation error,vsim:3053