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

版权声明:本文为博主原创文章,若需转载请注明来源。若文章有错误or疏漏,欢迎私信指教~ https://blog.csdn.net/little_starfish/article/details/82354848

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

Problem Description

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 problem,the pi,1-th,pi,2-th,…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 ii-th problem on t-th minute(or the t-th problem he solve is problem ii), he can get t×ai+bi points.(|ai|,|bi|<=le9).
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 n lines, the i-th line contains si+3 integers, 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*5+6=11 points.

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

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=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道题,接下来N行首先输入ai, bi, m
之后输入m个整数p1,p2,p3…pm
代表解答出第i个题可以获得 t * ai + bi的分数,但是解答第i个题的前提是已经解答出p1,p2…pm个题了
问可以获得的分数最大为多少(可以不做题)

思路

因为N比较小,可以想到用状压dp,取所有状态下的最大值即可
状压时,还要判断当前状态是否满足需要做的题已经做完了

AC代码

#include <bits/stdc++.h>
#define maxlen 1e15
using namespace std;
const int maxn=30;
typedef long long ll;
ll a[maxn],b[maxn],dp[(1<<20)+1];
int p[maxn][maxn];
bool check(int x,int y)  //判断当前状态是否合法
{
    if((x&(1<<y))==0)  //当前状态里是否有第y个题
        return false;
    if(dp[x^(1<<y)]==-1)  
        return false;
    for(int i=1;i<=p[y][0];i++){  //前面需要做的题是否做了
        if((x&(1<<p[y][i]))==0)
            return false;
    }
    return true;
}
ll get(int k)  //求当前问题是第几个解答出来的
{
    ll num=0;
    while(k){
        if(k&1)
            num++;
        k>>=1;
    }
    return num;
}
int main()
{
    int i,j,n;
    scanf("%d", &n);
    for(i=0;i<n;i++){  //从0开始
        scanf("%lld %lld %d", &a[i],&b[i], &p[i][0]);
        for(j=1;j<=p[i][0];j++){
            scanf("%d", &p[i][j]);
            p[i][j]--;
        }
    }
    ll ans=0;
    int all=(1<<n)-1;
    memset(dp,-1,sizeof(dp));  //初始化
    dp[0]=0;
    for(i=1;i<=all;i++){
        for(j=0;j<n;j++){
            if(check(i,j)){
                dp[i]=max(dp[i],dp[i^(1<<j)]+get(i)*a[j]+b[j]);  //取最大值
                ans=max(ans,dp[i]);  //取最大值
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/little_starfish/article/details/82354848