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. Versions 崩溃(Mac升级OS X Yonsemite 10.10)

    今天兴冲冲的升级到了OS X Yonsemite 10.10,结果发现SVN工具不能用了,于是找到一个暂时的解决的方法 1.打开目录~/.subversion/servers 2.在[global] ...

  2. 腾讯云上运行java程序过程

    1: 购买服务器(腾讯云,阿里云等) 2:安装centos操作系统: 3:安装jdkhttp://www.cnblogs.com/Amos-Turing/p/7403696.html 4:安装数据库( ...

  3. 开发笔记--java.lang.OutOfMemoryError: PermGen space异常处理

    第一次到公司开发项目,比起之前的小项目来说这次的项目特别大,以至于运行之后出现了java.lang.OutOfMemoryError: PermGen space的异常,从字面意思上来看是内存溢出的原 ...

  4. css 样式(checkbox开关、css按钮)

    checkbox开关 css .iosCheck { /* Blue edition */ } .iosCheck input { display: none; } .iosCheck i { dis ...

  5. cinder挂载卷的过程原理

    LVM名称介绍 PV:物理磁盘 VG:卷组,多个PV可以组成一个VG,一个VG可以划分成多个LV(逻辑卷). PP:物理区块,将一个VG逻辑的划分成连续的小块. LP:逻辑区块,若干个PP组成一个LP ...

  6. linux字符设备学习笔记【原创】

    1.申请设备号 int register_chrdev_region(dev_t from, unsigned count, const char *name) 指定从设备号from开始,申请coun ...

  7. Spring Boot2.0之整合JSP

    首先不建议整合JSP哈,spring boot 对jsp的支持力度不大.  内置tomcat不支持jsp. 注意:在创建项目时候一定是war类型的,而不是跟之前那个freemarker那种jar类型. ...

  8. Contiki Process概述

    本文涉及到的Protothread机制知识,在http://www.cnblogs.com/songdechiu/p/5793717.html 一.进程类型 进程类型主要有协同式(cooperativ ...

  9. python3 - 商品管理的程序,商品信息都存在一个json串里面

    商品管理的程序,商品信息都存在一个json串里面 1.查询商品信息 #校验商品是否存在 2.新增商品 # #校验商品是否存在 #校验价格是否合法 3.修改商品信息 ##校验商品是否存在 if chic ...

  10. 总结近期CNN模型的发展(一)---- ResNet [1, 2] Wide ResNet [3] ResNeXt [4] DenseNet [5] DPNet [9] NASNet [10] SENet [11] Capsules [12]

    总结近期CNN模型的发展(一) from:https://zhuanlan.zhihu.com/p/30746099 余俊 计算机视觉及深度学习   1.前言 好久没有更新专栏了,最近因为项目的原因接 ...