AC Challenge

  • 30.04%
  • 1000ms
  • 128536K
 

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

题目来源

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

状压dp。

#include <bits/stdc++.h>
#define MAX 21
typedef long long ll;
using namespace std;
const int INF = 0x3f3f3f3f; ll a[MAX],b[MAX];
ll dp[<<];
vector<int> v[MAX]; int main(void)
{
int n,num,temp,i,j,k;
scanf("%d",&n);
for(i=;i<=n;i++) {
scanf("%lld %lld",&a[i],&b[i]);
scanf("%d",&num);
while(num--) {
scanf("%d",&temp);
v[i].push_back(temp);
}
}
memset(dp,,sizeof(dp));
for(i=;i<(<<n);i++){
int f=;
for(j=;j<=n;j++){
if(!((<<(j-))&i)) continue;
for(k=;k<v[j].size();k++){
if(!((<<(v[j][k]-))&i)){
f=;
break;
}
}
if(f==) break;
}
if(f==) continue;
for(j=;j<=n;j++){
if(!((<<(j-))&i)) continue;
int S=i;
int c=;
while(S){
if(S&) c++;
S>>=;
}
dp[i]=max(dp[i],dp[i^(<<(j-))]+c*a[j]+b[j]);
//printf("(%d %d %d %lld)",i,c,j,dp[i]);
}
}
printf("%lld\n",dp[(<<n)-]);
return ;
}

ACM-ICPC2018南京网络赛 AC Challenge(一维状压dp)的更多相关文章

  1. 南京网络赛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. AC Challenge(状压dp)

    ACM-ICPC 2018 南京赛区网络预赛E: 题目链接https://www.jisuanke.com/contest/1555?view=challenges Dlsj is competing ...

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

    https://nanti.jisuanke.com/t/30994 题意 给你n个题目,对于每个题目,在做这个题目之前,规定了必须先做哪几个题目,第t个做的题目i得分是t×ai+bi问最终的最大得分 ...

  4. 2019年第十届蓝桥杯省赛-糖果(一维状压dp)

    看到20的数据量很容易想到状压dp. 开1<<20大小的数组来记录状态,枚举n个糖包,将其放入不同状态中(类似01背包思想) 时间复杂度O(n*(2^20)). import java.u ...

  5. HDU3247 Resource Archiver (AC自动机+spfa+状压DP)

    Great! Your new software is almost finished! The only thing left to do is archiving all your n resou ...

  6. 2013 ACM/ICPC 南京网络赛F题

    题意:给出一个4×4的点阵,连接相邻点可以构成一个九宫格,每个小格边长为1.从没有边的点阵开始,两人轮流向点阵中加边,如果加入的边构成了新的边长为1的小正方形,则加边的人得分.构成几个得几分,最终完成 ...

  7. HDU - 3247 Resource Archiver (AC自动机,状压dp)

    \(\quad\)Great! Your new software is almost finished! The only thing left to do is archiving all you ...

  8. 【noip模拟赛5】细菌 状压dp

    [noip模拟赛5]细菌   描述 近期,农场出现了D(1<=D<=15)种细菌.John要从他的 N(1<=N<=1,000)头奶牛中尽可能多地选些产奶.但是如果选中的奶牛携 ...

  9. HDU 3247 Resource Archiver (AC自动机+BFS+状压DP)

    题意:给定 n 个文本串,m个病毒串,文本串重叠部分可以合并,但合并后不能含有病毒串,问所有文本串合并后最短多长. 析:先把所有的文本串和病毒都插入到AC自动机上,不过标记不一样,可以给病毒标记-1, ...

随机推荐

  1. The connection between feature spaces and smoothness is not obvious, and is one of the things we’ll discuss in the course.

    http://www.gatsby.ucl.ac.uk/~gretton/coursefiles/lecture4_introToRKHS.pdf

  2. session,cookie的理解(总结)

    会话(Session)跟踪是Web程序中常用的技术,用来跟踪用户的整个会话.常用的会话跟踪技术是Cookie与Session.Cookie通过在客户端记录信息确定用户身份,Session通过在服务器端 ...

  3. Linux安装ElasticSearch启动报错的解决方法

    Linux安装ElasticSearch后,ElasticSearch是不能用root用户启动的,以root用户启动会报错Refer to the log for complete error det ...

  4. P5111 zhtobu3232的线段树

    P5111 zhtobu3232的线段树 维护左子树右子树的贡献和跨区间贡献 #include<bits/stdc++.h> using namespace std; typedef lo ...

  5. DOM的构建与优化

    一.构建模块 HTML描述了一个页面的结构.浏览器会将它转换成一种他们能够理解的格式——文档对象模型(DOM),浏览器引擎有一段特殊的代码叫做解析器,将数据从一种格式转换成另外一种格式. 一个HTML ...

  6. importlib模块 反射字符串的对象

    通过 importlib模块 反射字符串的对象 Python 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609] on linux ...

  7. poj The Settlers of Catan( 求图中的最长路 小数据量 暴力dfs搜索(递归回溯))

    The Settlers of Catan Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1123   Accepted: ...

  8. 51nod 80分算法题

    1537:见前几篇. 1627:题意:给定n,m的网格(10^5),初始状态为(1,1),你每次可以瞬移到右下方(不可以同行同列逗留)任何一个方格里,求移动到n,m的方案数. 一句话题解:首先很容易想 ...

  9. ZOJ 3640 Help Me Escape:期望dp

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3640 题意: 有一个吸血鬼被困住了,他要逃跑... 他面前有n条 ...

  10. listen 74

    Genes Link Touch and Hearing Sound and touch may seem completely separate, except possibly when play ...