ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Codeforce1176F Destroy it!

2020-10-12 22:31:46  阅读:256  来源: 互联网

标签:10 max turn m1 m2 cards Destroy Codeforce1176F


Description

You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game.

The boss battle consists of n turns. During each turn, you will get several cards. Each card has two parameters: its cost ci and damage di. You may play some of your cards during each turn in some sequence (you choose the cards and the exact order they are played), as long as the total cost of the cards you play during the turn does not exceed 3. After playing some (possibly zero) cards, you end your turn, and all cards you didn't play are discarded. Note that you can use each card at most once.

Your character has also found an artifact that boosts the damage of some of your actions: every 10-th card you play deals double damage.

What is the maximum possible damage you can deal during n turns?

Input

The first line contains one integer n (1≤n≤2⋅\(10^{5}\)) — the number of turns.

Then n blocks of input follow, the i-th block representing the cards you get during the i-th turn.

Each block begins with a line containing one integer ki (1≤ki≤2⋅\(10^{5}\)) — the number of cards you get during i-th turn. Then ki lines follow, each containing two integers cj and dj (1≤cj≤3, 1≤dj≤\(10^{9}\)) — the parameters of the corresponding card.

It is guaranteed that \(\sum_{i=1}^{n}\)ki≤2⋅\(10^{5}\).

Output

Print one integer — the maximum damage you may deal.

Solution

就是一个01背包加入了一些特殊的条件:
1.将这些物品分成n块,每块的质量之和不能超过3
2.当选到第10的倍数个数时,该数贡献翻倍
设f[i][j]表示做到第i个数,选了j个数的最大价值和
显然\(n^{2}\)我们无法接受,于是我们把j滚动
其他和01背包是一样的

Code

#include <cstdio>
#include <algorithm>
#include <cstring>
#define N 200001
#define open(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
int n,i,j,k,a,b,t,ma,mi,m1[N][10],m2[N],m3[N];
long long ans,f[N][10];
int main()
{
    open("destroy");
    scanf("%d",&n);
    for (i=1;i<=n;i++)
    {
        scanf("%d",&t);
        for (j=1;j<=t;j++)
        {
            scanf("%d%d",&a,&b);
            if (a==1)
            {
                if (b>m1[i][1]) m1[i][3]=m1[i][2],m1[i][2]=m1[i][1],m1[i][1]=b;else 
                if (b>m1[i][2]) m1[i][3]=m1[i][2],m1[i][2]=b;else 
                if (b>m1[i][3]) m1[i][3]=b;
            }
            if (a==2) m2[i]=max(m2[i],b);
            if (a==3) m3[i]=max(m3[i],b);
        }
    }
    memset(f,128,sizeof(f));
    f[0][0]=0;
    for (i=1;i<=n;i++)
    {
        for (j=0;j<=9;j++) f[i][j]=f[i-1][j];
        for (k=0;k<=9;k++)
        {
            if (f[i-1][k]>=0) 
            {
                if (m1[i][1])f[i][(k+1)%10]=max(f[i][(k+1)%10],f[i-1][k]+m1[i][1]*(k==9?2:1));
                if (m1[i][1]&&m1[i][2]) f[i][(k+2)%10]=max(f[i][(k+2)%10],f[i-1][k]+m1[i][1]*(k>=8?2:1)+m1[i][2]);
                if (m2[i]) f[i][(k+1)%10]=max(f[i][(k+1)%10],f[i-1][k]+m2[i]*(k==9?2:1));
                if (m1[i][1]&&m1[i][2]&&m1[i][3]) f[i][(k+3)%10]=max(f[i][(k+3)%10],f[i-1][k]+m1[i][1]*(k>=7?2:1)+m1[i][2]+m1[i][3]);
                if (m1[i][1]&&m2[i]) 
                {
                    ma=max(m1[i][1],m2[i]);mi=min(m1[i][1],m2[i]);
                    f[i][(k+2)%10]=max(f[i][(k+2)%10],f[i-1][k]+ma*(k>=8?2:1)+mi);
                }
                if (m3[i]) f[i][(k+1)%10]=max(f[i][(k+1)%10],f[i-1][k]+m3[i]*(k==9?2:1));
            }
        }
    }
    for (i=0;i<=9;i++) ans=max(ans,f[n][i]);
    printf("%lld",ans);
    return 0;
}

标签:10,max,turn,m1,m2,cards,Destroy,Codeforce1176F
来源: https://www.cnblogs.com/Sport-river/p/13806027.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有