博客目录

原题

题目链接

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

题目大意

有n个题目(n<=20),每个题目两个跟分数有关的属性a和b,每分钟都做且只做1道题,设一道题在第t分钟做,则这个题的得分公式为:a*t+b。注意:a或b可能是负数。

而且有些题目需要先完成另外一些题目(由数据给出)才可以提交这个题(题目保证满足拓扑结构,也就是无环)

问最大得分是多少。

思路

因为题目个数不超过20,所以枚举每个题目做和不做,最多有2的20次方种情况,也就是1e6的情况。以二进制形式枚举每个题目做/不做。设枚举变量为st,则0<= st < (1<<20)。

对于每种状态,枚举所有可以做且还没做的题目,进行状态转移。

设由状态st做了题i之后转移到的下一个状态为next,当前状态为st,枚举题目的变量为i。dp[x]表示到达状态x可以得到的最大分数。

则有状态转移方程:

dp[next]=max(由其它状态转移到next的分数,由st做了第i个题后转移到next的分数);

有初始化条件:dp[0]=0,表示一个题也不做分数为0

有答案:ans=max(dp[next])表示所有情况中最大分数。

具体细节见代码注释

AC代码

#include<bits/stdc++.h>
#include<cstring>
using namespace std;
struct node{
    int a,b;
};
node co[30];
int dp[1<<21];
int main(){
    int vec[30];
    int n,c,x;
    cin>>n;
    for(int i=0;i<n;i++){
        scanf("%d%d",&co[i].a,&co[i].b);
        scanf("%d",&c);
        vec[i]=0;
        for(int j=0;j<c;j++){
            scanf("%d",&x);
            vec[i]|=(1<<(x-1));//限制条件状压 
        }
    }
    #define inf 0x3f3f3f3f 
    memset(dp,-inf,sizeof(dp));//有负数 
    int maxst=1<<20;
    int t;
    int maxv=0;//最大分值。 
    dp[0]=0;
    for(int st=0;st<maxst;st++){
        if(st==-inf) //剪枝 
            continue;
        t=1;
        for(int j=st;j;j>>=1){
            t+=j&1;//1的个数就是时间t 
        }
        for(int i=0;i<n;i++){
            if(st>>i&1)
                continue;//第i题已经做过了 
            if((st|vec[i])>st)//是否可以做第i题 
                continue;//不可以做第i题 
            //完全满足做第i题的条件。
            int next=st|(1<<i);//做完第i题的状态 
            //dp[next]=max(由其它状态转移到next的分数,由st转移到next的分数);            
            dp[next]=max(dp[next],dp[st]+t*co[i].a+co[i].b);
            maxv=max(maxv,dp[next]);
        }
    }
    cout<<maxv<<endl; 
}

E. AC Challenge ACM-ICPC 2018 南京赛区网络预赛 状压dp + 枚举状态相关推荐

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

    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 南京赛区网络预赛 - AC Challenge(状压DP)

    ACM-ICPC 2018 南京赛区网络预赛 - AC Challenge 题意: 有n个题目,每个题目有一些信息,,第 t 个过第 i 题会得到分数 t*ai + bi 在过第 i 题前必须要先过  ...

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

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

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

  5. ACM-ICPC 2018 南京赛区网络预赛 Lpl and Energy-saving Lamps 线段树

    目录 ACM-ICPC 2018 南京赛区网络预赛 Lpl and Energy-saving Lamps 线段树 题面 题意 思路 ACM-ICPC 2018 南京赛区网络预赛 Lpl and En ...

  6. ACM-ICPC 2018 南京赛区网络预赛 B. The writing on the wall

    题目链接:https://nanti.jisuanke.com/t/30991 2000ms 262144K Feeling hungry, a cute hamster decides to ord ...

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

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

  8. ACM-ICPC 2018 南京赛区网络预赛(ABCDEFGHIJKL所有题题解大全)

    新高一蒟蒻队的第一次ACM-- 赛场上和队友时间安排不太恰当--只过了9题,第10题差半个小时2333--/还是自己太弱了 赛后经过一段时间把所有题全部A掉了2333-- A:题目链接 这道题在聊天中 ...

  9. ACM-ICPC 2018 南京赛区网络预赛:E :AC Challenge题解

    原题链接:AC Challenge 解析:题目要求求出最大分数,一共最多只有20题,故最多只有2^20种不同的状态,本题可以求出每一种状态的得分,取最高分即为答案(注:若最高分为负,则答案为0,对应题 ...

最新文章

  1. UltraEdit正则表达式介绍及实例
  2. Android 启动分析 1
  3. OpenGL Primitive Restart原始重启的实例
  4. 使用Docker Compose部署SpringBoot应用
  5. 统计数据库中各个表和空间使用情况
  6. 关于BDC、SSP搜索相关解决方案 的数据结构
  7. inner join、 left join 、right join、full outer join之间的区别
  8. 单列变双列css_css – 右对齐双列布局丢失水平滚动条
  9. VS2017透明背景和皮肤设置
  10. adodb 连接oracle php,c# 利用ADODB连接ORACLE数据库
  11. java程序员推荐app_Java程序员面试大全app
  12. python excel 填充颜色_pandas to_excel 添加颜色操作
  13. 计算机桌面隔几秒闪一下,电脑最近怎么老是隔一段时间显示器就要闪一下
  14. Android 蓝牙监听与扫描
  15. SSL 1231 容易的网络游戏
  16. vue-i18n 用法
  17. 如何完成上传图片到腾讯云
  18. 狂神说Java--Java学习笔记(基础合集)
  19. 封头名义厚度如何圆整_关于几种形式封头特点的比较
  20. Spark高效数据分析03、Spark SQL

热门文章

  1. 计算机网络 四、五层协议体系结构-----数据链路层
  2. JAVAMail 使用imap协议分析邮件
  3. 用python对股票进行可视化分析_股票分析 | 用Python玩玩A股股票数据分析-可视化部分...
  4. ESP32 ESP-IDF增加自定义components 注意事项
  5. input lable 事件
  6. Adobe Photoshop CS6
  7. Android | navigation入门详解
  8. Java基础1语法准备
  9. 17joys用户管理 添加用户
  10. HTML5+CSS3网页设计从基础到入门——合并单元格