首页 > 其他分享 >P9676 [ICPC2022 Jinan R] Skills Solution

P9676 [ICPC2022 Jinan R] Skills Solution

时间:2024-09-27 16:24:59浏览次数:1  
标签:ICPC2022 P9676 ZYC 10 Skills Yc ch using define

P9676 [ICPC2022 Jinan R] Skills Solution

拿到题目之后我们先考虑一个朴素dp:记 \(f_{i,0/1/2,x,y}\) 表示第 \(i\) 天,我们学习第 1/2/3 个技能,同时按照序号顺延下去的另两个技能分别有 \(x,y\) 天未学习的最大经验总和。这很明显是一个 \(O(n^3)\) 的 dp,转移方程比较简单。我们考虑优化。
第一维明显可以滚动数组滚掉,于是空间复杂度来到了 \(O(n^2)\)。于是没有什么明显的优化空间了,我们考虑分析特殊性质:
如果我在某一天学习了某项技能,那么我之后一定不能让它的经验值降为 0 ,因为如果这样的话我们很明显在那一天学习其它技能是不劣甚至更优的。于是很明显有一个未学习天数的限制,不难算出这个天数是 \(2\sqrt{a_i}\),于是时间复杂度降到了 \(O(n^2)\),可以通过本题。
code

#include <bits/stdc++.h>
using namespace std;

#define Debug printf("ZYC\n")
using Yc = long long;
using pii = pair<Yc, Yc>;

namespace Fast_Read {

inline Yc read() {
  Yc x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}

inline void write(Yc x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
  return;
}
}  // namespace Fast_Read

const Yc zyc = 1000 + 10;
const Yc limit = 210;

using namespace Fast_Read;
#define pc putchar
#define ps puts
#define pr printf
#define mk make_pair

Yc n, a[zyc][3], f[2][3][limit + 10][limit + 10], nxt[3];

inline void chmax(Yc &a, Yc b) { a = max(a, b); }

signed main() {
#define ZYC_
#ifdef ZYC_
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
#endif  // ZYC_

  Yc T = read();
  while (T--) {
    n = read();
    for (Yc i = 1; i <= n; i++)
      for (Yc j = 0; j < 3; j++) a[i][j] = read();
    memset(f, 0, sizeof(f));
    Yc cur = 0;
    for (Yc i = 0; i < n; cur ^= 1, i++) {
      for (Yc j = 0; j < 3; j++) {
        for (Yc k = 0; k < limit && k <= i; k++) {
          for (Yc l = 0; l < limit && l <= i; l++) {
            Yc nx = k ? k + 1 : 0, ny = l ? l + 1 : 0;
            if (nx < limit && ny < limit)
              chmax(f[cur ^ 1][j][nx][ny],
                    f[cur][j][k][l] - nx - ny + a[i + 1][j]);
            if (nx < limit)
              chmax(f[cur ^ 1][(j + 1) % 3][ny][1],
                    f[cur][j][k][l] - ny - 1 + a[i + 1][(j + 1) % 3]);
            if (ny < limit)
              chmax(f[cur ^ 1][(j + 2) % 3][1][nx],
                    f[cur][j][k][l] - nx - 1 + a[i + 1][(j + 2) % 3]);
          }
        }
      }
    }
    Yc ans = 0;
    for (Yc j = 0; j < 3; j++)
      for (Yc k = 0; k < limit && k <= n; k++)
        for (Yc l = 0; l < limit && l <= n; l++) chmax(ans, f[cur][j][k][l]);
    write(ans), ps("");
  }
  return 0;
}

标签:ICPC2022,P9676,ZYC,10,Skills,Yc,ch,using,define
From: https://www.cnblogs.com/yxans/p/18435990

相关文章

  • POLIR-Society-Organization-Management:Transform Business Skills with Proven Simu
    CapsimManagementSimulations,Inc.PrivacyPolicyTermsAccessibilityPolicyTransformBusinessSkillswithProvenSimulationandAssessmentTechnologyProvideimmersive,hands-onlearningexperiencesinareal-worldenvironment–soyoucanmeasureand......
  • P9058 [Ynoi2004] rpmtdq 与 P9678 [ICPC2022 Jinan R] Tree Distance
    思路:注意到点对数量有\(N^2\)个,考虑丢掉一些无用的点对。对于点对\((x_1,y_1),(x_2,y_2)\),满足\(x_1\lex_2<y_2\ley_1\),即区间\([x_2,y_2]\)被\([x_1,y_1]\)包含,此时满足若询问到了\([x_1,y_1]\),则一定会询问到\([x_2,y_2]\)。若满足\(\operatorname{dis}(x_1......
  • P9668 [ICPC2022 Jinan R] Torch 题解
    思路考虑使用矩阵模拟这个过程。首先,我们可以设初值为:\[\begin{bmatrix}0&1\end{bmatrix}\]表示瘦子初始走\(0\)米,胖子初始走\(1\)米。考虑瘦子走一步。由于瘦子每走一步都不能超过胖子,我们可以使用\((\min,+)\)矩乘来维护这个性质。那么瘦子走一步是:\[\begin{bma......
  • ENGL642 Research Skills Question
    ENGL642 ResearchSkillsAssignmentQuestionSemesterTwo2023-2024There is one assessed assignment for the module ENGL642 Research Skills. The assignment requiresyouto produce a research proposal (see section‘the research proposal’......
  • P9669 [ICPC2022 Jinan R] DFS Order 2
    P9669[ICPC2022JinanR]DFSOrder2树形dp+回退背包dfs的过程时走到\(u\),如果走进一个子树后要回到\(u\),那么这个子树一定全部遍历了一遍。所以方案数会跟子树遍历的方案数有关,可以预处理。设\(h_u\)表示\(u\)子树的遍历方案,假如\(u\)有\(m\)个儿子,那么有\(h_u=......
  • Unity类银河恶魔城学习记录10-14 p102 Applying damage to skills and clean up源代码
     Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释,可供学习Alex教程的人参考此代码仅为较上一P有所改变的代码【Unity教程】从0编程制作类银河恶魔城游戏_哔哩哔哩_bilibiliEntity.csusingSystem.Collections;usingSystem.Collections.Generic;usingUnit......
  • Sparse Table Advanced Skills
    Storeatupleof(valueofmaximum,indexofmaximum,valueofthesecondmaximum).Tomergetwosegments,wecompareiftheindicesofthemaximumsarethesame.Theycanpossiblybethesamebecauseweoftenqueryintersectingsegmentsinthesparsetab......
  • P9361 [ICPC2022 Xi'an R] Contests
    更好的阅读体验P9361[ICPC2022Xi'anR]Contests首先观察一下性质,每个\(l\)在每场比赛里一定是对应着某个前缀。发现题目要求的是最小的满足要求的\(l\),最暴力的大概是维护五个指针,每次答案\(+1\),然后尝试跳一步,什么时候某个前缀包含了\(x\)当前的计数器就是答案。考......
  • ICPC2022 Xi'an R A Bridge
    洛谷传送门QOJ传送门感觉很妙啊,应该不止蓝吧?首先一个转化是每次建桥操作就相当于交换两条链的后半部分,可以看看扶苏那篇题解的图。我们将每个点表示为形如\((x,y)\)的二元组表示它初始在第\(x\)行第\(y\)列,按\(y\)为键值排序,那么一次询问就是查询一条链的最大值。......
  • The importance of learning basic skills
    参考范文1TheImportanceofReadingLiteratureLiteratureisacknowledgedasthemostpreciousproductofhumancivilizationandwisdom,especiallybyourteachers.Sotheyalwaysasktheirstudentstoreadasmanyasliteraryworks.Justasthedrawi......