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;
    }
    
    如果自己说什麽都做不到而什麽都不去做的话,那就更是什麽都做不到,什麽都不会改变,什麽都不会结束.
  • 相关阅读:
    修改Win7远程桌面端口【适用XP/2003】
    Mysql Select语句详情
    SqlServer之连接
    MySql数据类型分析(日期时间类型) Part5
    MySql数据类型分析(银行家舍入法) Part3
    MySql数据类型分析(数值(小数型)类型) Part2
    MySql数据类型分析(数值(整形)类型) Part1
    WP系统一次订阅,终身锁屏同时显示农历和天气
    c# 操作 XML(增 ,删 , 改 , 查)
    Postgresql 读取txt到DB 插入或更新
  • 原文地址:https://www.cnblogs.com/Sport-river/p/13806027.html
Copyright © 2011-2022 走看看