题目链接:https://codeforces.com/gym/102056/problem/I

Warm sunshine, cool wind and a fine day, while the girl watching is pursuing in chaos. Rikka reached out her hand and got the garland on her head, finding LCR with the immortal smile. The dream ended up waking, but the doubts will never disappear. In the end, without knowing about LCR, Rikka was invited to Shuyuan Men, a street of Chinese traditional arts in Xi'an.

"Is it enough to use the stored wires?"

"No problem... Those leaders are only concerned about expanding EC Final for the school's and their 'achievements'. All chores are ours. It is fine to simply connect those wiring boards in the series for each row."

Their conversation engaged Rikka. Feeling strange, she decided to follow them. But before all, she needs to beat the devil in her heart.

Rikka has an aggressivity $A$ and an increment $D$ of it, which are both $0$ initially. There are $n$ rounds in total. For $i=1,2,…,n$, at the beginning of $i$-th round Rikka's aggressivity $A$ increases by the increment $D$, and then she can do one of the following:

Attack and cause a damage of $(A+a_i)$.
Use the Omnipotent Garland from LCR to increase the increment $D$ by $b_i$.
Use her Schwarz Sechs Prototype Mark II to increase the aggressivity $A$ by $c_i$.
Rikka wonders the maximal possible damage she could cause in total. Could you help her?

Input
The first line contains a single integer $T (1 \le T \le 10)$, the number of test cases. Then $T$ test cases follow.

The input format of each test case is as follows:

The first line contains a single integer $n (1 \le n \le 100)$, the number of rounds.

The following $n$ lines contain ${a_i},{b_i},{c_i}$ for $i=1,2,…,n$. The $i$-th line among them contains three integers $a_i,b_i,c_i (1 \le a_i,b_i,c_i \le 10^9)$ separated by spaces in order.

It is guaranteed that the sum of $n$ in all test cases is at most 100.

Output
Output T lines; each line contains one integer, the answer to that test case.

Example
input
3
2
3 1 2
3 1 2
3
3 1 2
3 1 2
3 1 2
5
3 1 2
3 1 2
3 1 2
3 1 2
3 1 2
output
6
10
24

题意:

打怪,有 $A$ 的攻击力,有 $D$ 的成长,初始均为 $0$,有 $n$ 轮。

同时有三个数组 $a[1:n], b[1:n], c[1:n]$。

对于每一轮:

  首先,攻击力永久性成长 $A = A + D$;然后,在下面三个选择中选择一种行为:

  ①、发起进攻,产生 $A + a_i$ 的伤害。

  ②、增加成长 $D = D + b_i$。

  ③、永久性增加攻击力 $A = A + c_i$。

问产生最大总伤害为多少。

题解:

onsite的时候,正向DP想不出来,没考虑逆向的DP。

不妨先将 $dp[i]$ 所表达的状态是从第 $i$ 轮开始进行攻击,到 $n$ 轮结束,那么自然地,其所存储的值是产生最大的伤害。

同时,假设 $dp[i+1]$ 已知,那么如果在第 $i+1$ 轮前面加一轮,不难计算第 $i$ 轮的三种选择产生的影响:

  第 $i$ 轮选择①,则多产生 $a_i$ 的伤害。

  第 $i$ 轮选择②,则成长增加了 $b_i$,假设其后在第 $j$ 轮进行一次攻击,则会多产生伤害 $(j-i) \cdot b_i$。

  第 $i$ 轮选择③,则攻击力增加了 $c_i$,假设其后在第 $j$ 轮进行一次攻击,则会比原来产生的伤害增加 $c_i$。

不妨为 $dp[i]$ 再加两个状态:从第 $i$ 轮起,到第 $n$ 轮总共进行了 $cnt$ 次攻击;这 $cnt$ 次攻击的编号之和为 $sum$。

这样一来,上述第 $i$ 轮的三种选择,多产生的伤害分别为:$a_i$,$(sum-cnt \cdot i) \cdot b_i$ 和 $cnt \cdot c_i$。

总结一下,就是 $dp[i][cnt][sum]$ 代表:假设当前游戏是从第 $i$ 轮开始进行攻击的,到第 $n$ 轮结束,一共进行了 $cnt$ 次攻击,它们的轮编号之和为 $sum$,总共最大能产生多少伤害。

那么显然的,递推的起点就是 $dp[n][1][n] = a_n$;而 $dp[1][\cdots][\cdots]$ 中的最大值即为答案。

而状态转移可以如下进行倒推:

① $dp[i][cnt][sum] = max(dp[i][cnt][sum], dp[i+1][cnt-1][sum-i] + a_i )$

② $dp[i][cnt][sum] = max(dp[i][cnt][sum], dp[i+1][cnt][sum] + (sum-cnt \cdot i) \cdot b_i )$

③ $dp[i][cnt][sum] = max(dp[i][cnt][sum], dp[i+1][cnt][sum] + cnt \cdot c_i )$

然后,还有一个需要注意的点是,这样一来 $dp[i][cnt][sum]$ 的大小是 $100 \times 100 \times (1+\cdots+100)$,会MLE。需要进行滚动优化。

AC代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. int n;
  5. ll dp[][][];
  6. ll a[],b[],c[];
  7. int main()
  8. {
  9. ios::sync_with_stdio();
  10. cin.tie(), cout.tie();
  11.  
  12. int T;
  13. cin>>T;
  14. while(T--)
  15. {
  16. cin>>n;
  17. for(int i=;i<=n;i++) cin>>a[i]>>b[i]>>c[i];
  18.  
  19. memset(dp,,sizeof(dp));
  20. dp[n&][][n]=a[n];
  21. for(int i=n-;i>=;i--)
  22. {
  23. for(int j=;j<=n-i;j++)
  24. {
  25. int down=(i+i+j)*(j-)/+n, up=(n+n-j+)*j/;
  26. for(int k=down;k<=up;k++)
  27. {
  28. dp[i&][j+][k+i]=max(dp[i&][j+][k+i],dp[(i+)&][j][k]+a[i]);
  29. dp[i&][j][k]=max(dp[i&][j][k],dp[(i+)&][j][k]+j*c[i]);
  30. dp[i&][j][k]=max(dp[i&][j][k],dp[(i+)&][j][k]+(k-j*i)*b[i]);
  31. }
  32. }
  33. }
  34. ll ans=;
  35. for(int j=;j<=n;j++) for(int k=;k<=;k++) ans=max(ans,dp[][j][k]);
  36. cout<<ans<<endl;
  37. }
  38. }

Gym 102056I - Misunderstood … Missing - [DP][The 2018 ICPC Asia-East Continent Final Problem I]的更多相关文章

  1. 2018 ICPC Asia Singapore Regional A. Largest Triangle (计算几何)

    题目链接:Kattis - largesttriangle Description Given \(N\) points on a \(2\)-dimensional space, determine ...

  2. 2018-2019 ACM-ICPC, Asia East Continent Finals I. Misunderstood … Missing(dp)

    题目链接: http://codeforces.com/gym/102056/problem/I 题意: 人物有l两个属性分别是$A,D$ 每个回合人物$A\pm D$ 每个回合有三个选择分别是: 1 ...

  3. Gym 102056L - Eventual … Journey - [分类讨论][The 2018 ICPC Asia-East Continent Final Problem L]

    题目链接:https://codeforces.com/gym/102056/problem/L LCR is really an incredible being. Thinking so, sit ...

  4. Gym - 101981M The 2018 ICPC Asia Nanjing Regional Contest M.Mediocre String Problem Manacher+扩增KMP

    题面 题意:给你2个串(长度1e6),在第一个串里找“s1s2s3”,第二个串里找“s4”,拼接后,是一个回文串,求方案数 题解:知道s1和s4回文,s2和s3回文,所以我们枚举s1的右端点,s1的长 ...

  5. Gym - 101981K The 2018 ICPC Asia Nanjing Regional Contest K.Kangaroo Puzzle 暴力或随机

    题面 题意:给你1个20*20的格子图,有的是障碍有的是怪,你可以每次指定上下左右的方向,然后所有怪都会向那个方向走, 如果2个怪撞上了,就融合在一起,让你给不超过5w步,让所有怪都融合 题解:我们可 ...

  6. Gym - 101981G The 2018 ICPC Asia Nanjing Regional Contest G.Pyramid 找规律

    题面 题意:数一个n阶三角形中,有多少个全等三角形,n<=1e9 题解:拿到题想找规律,手画开始一直数漏....,最后还是打了个表 (打表就是随便定个点为(0,0),然后(2,0),(4,0), ...

  7. Gym - 101981I The 2018 ICPC Asia Nanjing Regional Contest I.Magic Potion 最大流

    题面 题意:n个英雄,m个怪兽,第i个英雄可以打第i个集合里的一个怪兽,一个怪兽可以在多个集合里,有k瓶药水,每个英雄最多喝一次,可以多打一只怪兽,求最多打多少只 n,m,k<=500 题解:显 ...

  8. Gym - 101981D The 2018 ICPC Asia Nanjing Regional Contest D.Country Meow 最小球覆盖

    题面 题意:给你100个三维空间里的点,让你求一个点,使得他到所有点距离最大的值最小,也就是让你找一个最小的球覆盖掉这n个点 题解:红书模板题,这题也因为数据小,精度也不高,所以也可以用随机算法,模拟 ...

  9. Gym - 101981J The 2018 ICPC Asia Nanjing Regional Contest J.Prime Game 计数

    题面 题意:1e6的数组(1<a[i]<1e6),     mul (l,r) =l × (l+1) ×...× r,  fac(l,r) 代表 mul(l,r) 中不同素因子的个数,求s ...

随机推荐

  1. CentOS 7 安装 Oracle 11.2.0.4

    一.安装环境 CentOS Linux release 7.2.1511 (Core) Oracle Database 11g Release 2 (11.2.0.4) 二.安装前准备 2.1 修改主 ...

  2. PHPStrom激活方法

    直接用浏览器打开 http://idea.lanyus.com/ 点击页面中的“获得注册码”, 然后在注册时切换至Activation Code选项,输入获得的注册码一长串字符串 如果提示红字体信息, ...

  3. 【PHP】PHP 7.4 新特性

    PHP 7.4 预计在 2019 年年末就会正式发布了,本文先来看看一下 PHP 7.4 的新特性. 1.预加载 预加载的实现理论上是可以为 PHP 带来很大的性能提升的.比如说:现在传统的 PHP ...

  4. 网页出现400 Bad Request Request Header Or Cookie Too Large错误的解决方法

    在开发项目过程中,突然遇到400 Bad Request Request Header Or Cookie Too Large的报错,我也是第一次出现这样的错误,感觉还是挺新奇的. 分析下出现错误的原 ...

  5. Linux服务器CPU使用率较低但负载较高

    CPU使用率较低但负载较高 问题描述 Linux 系统没有业务程序运行,通过 top 观察,类似如下图所示,CPU 很空闲,但是 load average 却非常高,如下图所示. 处理办法 load ...

  6. glide引出恶心的git submodule

      起因 某一天一个同事,在看那个glide,然后我路过,看到他为何不编译“glide”项目(他说,编译中出错,反正都是看源码而已,所以就懒得搞,然后我出于“好心”,给他弄一下,我擦) 报错: Pro ...

  7. UltraVNC 简体中文版 1.2.2.1

    1.专门针对WinXP进行编译,同时适用XP之后的Windows版本(XP/Vista/8.1/10/2003/2008/2012): 2.配置低的计算机,Win8.1之前的系统,需要安装Mirror ...

  8. return返回两个三元表达式的和,返回不正确,同样要注意在JavaScript中,也是如此

    public string b() { string b = ""; "; } public int c() { public string b() { string b ...

  9. php异步执行其他程序

    这里的“其他程序”,可能是linux命令,可能是其他的php文件. 网上说法有四种.分别为: 1.通过加载页面的时候通过ajax技术异步请求服务器 2.通过popen()函数 3.通过curl扩展 4 ...

  10. 深度讲解 .net session 过期机制

    [参考]net session过期 原理及解决办法 [参考]深入理解session过期机制