zoukankan      html  css  js  c++  java
  • Codeforce1176F Destroy it!

    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;
    }
    
    如果自己说什麽都做不到而什麽都不去做的话,那就更是什麽都做不到,什麽都不会改变,什麽都不会结束.
  • 相关阅读:
    27. 移除元素
    axios调用webapi报错
    MySql重装以后,修改数据库路径,打开以前的数据库报Table 'XX库.XX表' doesn't exist错误的解决办法
    SqlServer2012,设置指定数据库对指定用户开放权限
    win10无法访问服务器上的共享文件夹怎么设置,提示:你不能访问此共享文件夹,因为你组织的安全策略阻止未经身份验证的来宾访问
    Vs2017的git的坑
    jira6.3.6创建问题不自动发邮件通知的问题
    在windows下面配置redis集群遇到的一些坑
    SqlServer2008 无法修改表,超时时间已到 在操作完成之前超时解决方法
    小程序中也可以使用三元运算符且可嵌套使用
  • 原文地址:https://www.cnblogs.com/Sport-river/p/13806027.html
Copyright © 2011-2022 走看看