ICPC2018南京网络赛 AC Challenge(一维状压dp)

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[1<<20];
vector<int> v[MAX];

int main(void)
{
    int n,num,temp,i,j,k;
    scanf("%d",&n);
    for(i=1;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,0,sizeof(dp));
    for(i=0;i<(1<<n);i++){
        int f=0;
        for(j=1;j<=n;j++){
            if(!((1<<(j-1))&i)) continue;
            for(k=0;k<v[j].size();k++){
                if(!((1<<(v[j][k]-1))&i)){
                    f=1;
                    break;
                }
            }
            if(f==1) break;
        }
        if(f==1) continue;
        for(j=1;j<=n;j++){
            if(!((1<<(j-1))&i)) continue;
            int S=i;
            int c=0;
            while(S){
                if(S&1) c++;
                S>>=1;
            }
            dp[i]=max(dp[i],dp[i^(1<<(j-1))]+c*a[j]+b[j]);
            //printf("(%d %d %d %lld)",i,c,j,dp[i]);
        }
    }
    printf("%lld\n",dp[(1<<n)-1]);
    return 0;
}

原文地址:https://www.cnblogs.com/yzm10/p/9571205.html

时间: 2024-11-05 22:57:45

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

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

https://nanti.jisuanke.com/t/30994 题意 给你n个题目,对于每个题目,在做这个题目之前,规定了必须先做哪几个题目,第t个做的题目i得分是t×ai+bi问最终的最大得分是多少? 分析 枚举所有状态,在转移时判断合法性,然后直接转移就好了.dp初始化为-inf,边界值dp[0]=0; #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring&g

[AC自动机+spfa+状压dp] hdu 3247 Resource Archiver

题意: 给n个本源串,m个病毒串 求一个最多的长度的单词包含所有的本源串并不包含任意一个病毒串 串均为01串 思路: 只有10个本源串 一开始想的是直接建立完trie图 然后在图上直接spfa 结果发现 dis[60005][1030] 超内存了 这个时候就要想到 其实只有节点的mark值大于0的节点是我们需要用的 就是那些含有状压权值的节点 那么我们先记录下这些节点是哪些 然后发现其实这些不到100个节点 所以跑100遍spfa 求出两两之间的最短路 然后用这个距离 去状压dp 数组就成了 d

2015广东工业大学ACM校赛 I 游戏王 (状压dp)

Problem I: 游戏王 Description 小学的时候,Stubird非常喜欢玩游戏王,有一天,他发现了一个绝佳的连锁组合,这个连锁组合需要6张卡, 可是他一张都没有,但是他的那些朋友们有,不过当然,他们不会白给,不过也不排除有人和他交情好,送给他了. 不过他们有成全别人的美德,当他们看到Stubird已经有某些他们喜欢的卡的时候,他们会给他优惠,或者更贵也说不定 嘛不过,你可以把有的卡片藏起来,不告诉他们,来获得更低的价格. 问他最少需要多少钱才可以集齐所有的卡. Input 第一行

HDU-5025 2014广州网络赛 Saving Tang Monk 状压+BFS

给出一个N*N的矩阵,开启牢门需要收集齐m种钥匙,且必须收集了前i-1种钥匙才能收集第i种钥匙,最终收集齐了回到关押唐僧的房间拯救唐僧,经过一个'S'的房间时需要额外耗时把蛇打死,蛇最多5条,所以状压一下用优先队列BFS求最小时间即可. #include <iostream> #include <cstdio> #include <cmath> #include <queue> #include <vector> #include <cst

2014牡丹江网络预选赛D题(状压DP)zoj3812

We Need Medicine Time Limit: 10 Seconds      Memory Limit: 65536 KB      Special Judge A terrible disease broke out! The disease was caused by a new type of virus, which will lead to lethal lymphoedema symptom. For convenience, it was named LL virus.

2018ICPC南京网络赛

2018ICPC南京网络赛 A. An Olympian Math Problem 题目描述:求\(\sum_{i=1}^{n} i\times i! \%n\) solution \[(n-1) \times (n-1)! \% n= (n-2)!(n^2-2n+1) \%n =(n-2)!\] \[(n-2+1)\times (n-2)! \% n= (n-3)!(n^2-3n+2) \%n =(n-3)! \times 2\] 以此类推,最终只剩下\(n-1\) 时间复杂度:\(O(1)\

2019ICPC南京网络赛A题 The beautiful values of the palace(三维偏序)

2019ICPC南京网络赛A题 The beautiful values of the palace https://nanti.jisuanke.com/t/41298 Here is a square matrix of n * nn?n, each lattice has its value (nn must be odd), and the center value is n * nn?n. Its spiral decline along the center of the squar

【HDU3341】 Lost&#39;s revenge (AC自动机+状压DP)

Lost's revenge Time Limit: 5000MS Memory Limit: 65535KB 64bit IO Format: %I64d & %I64u Description Lost and AekdyCoin are friends. They always play "number game"(A boring game based on number theory) together. We all know that AekdyCoin is t

HDU 5131 Little Zu Chongzhi&#39;s Triangles (状压DP +2014广州现场赛)

题目链接:HDU 5131 Little Zu Chongzhi's Triangles 题意:给出一些线段,在其中选出3根组成三角形,问用这些线段组成的所有三角形的最大面积是多少. 7 3 4 5 3 4 5 90 两个三角形是(3,3,4),(5,5,4). 思路:N最大12,状态压缩,把所有可能组成的三角形存起来.A&B==0则说明A|B状态是有效的. 贪心也能过..为什么? AC代码: #include <stdio.h> #include <string.h> #