Gym 102056I - Misunderstood … Missing - [DP][The 2018 ICPC Asia-East Continent Final Problem I]

I. Misunderstood … Missing

time limit per test

1.0 s

memory limit per test

256 MB

input

standard input

output

standard output

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 AA and an increment DD of it, which are both 00 initially. There are nn rounds in total. For i=1,2,…,ni=1,2,…,n, at the beginning of ii-th round Rikka's aggressivity AA increases by the increment DD, and then she can do one of the following:

  1. Attack and cause a damage of (A+ai)(A+ai).
  2. Use the Omnipotent Garland from LCR to increase the increment DD by bibi.
  3. Use her Schwarz Sechs Prototype Mark II to increase the aggressivity AA by cici.

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≤T≤10)T (1≤T≤10), the number of test cases. Then TT test cases follow.

The input format of each test case is as follows:

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

The following nn lines contain {ai},{bi},{ci}{ai},{bi},{ci} for i=1,2,…,ni=1,2,…,n. The ii-th line among them contains three integers ai,bi,ci (1≤ai,bi,ci≤109)ai,bi,ci (1≤ai,bi,ci≤109) separated by spaces in order.

It is guaranteed that the sum of nn in all test cases is at most 100100.

Output

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

Example

input

Copy

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

Copy

6
10
24

 

OJ題號

Gym 102056I - Misunderstood … Missing - [DP][The 2018 ICPC Asia-East Continent Final Problem I]

https://codeforces.com/gym/102056/problem/I

 

簡單題意

有兩種值A,D,A代表攻擊一次怪獸能對怪獸造成的傷害。D代表每回合開始時A的增量。初始值均爲0

給出三種操作,求使用這三種操作在n回合後可以達到的對怪獸傷害的最大值:

1.攻擊怪獸,造成A+a[i]傷害。

2.不攻擊怪獸,但使D增加b[i]。

3.不攻擊怪獸,但使A增加c[i]。
 

正解思路

DP好題,這個講的很好!https://www.cnblogs.com/dilthey/p/10132650.html

注意枚舉攻擊編號的時候,假設分別在p1,p2,p3, …… ,px處打出傷害,那麼,會有傷害的額外值增加:(p1 - i + p2 - i + p3 - i + …… + px - i) * b[i] = (p1 + p2 + p3 + ……  + px - x * i) * b[i];那麼,我們得去遍歷(p1 + p2 + p3 + …… + px)的狀態,這個狀態其實可以看作:如果我們從後面開始向前面取的話,那麼就是從N、N-1、N-2、…… 、N-j+1,等於(N + N - j + 1)* j / 2;同樣的道理,我們可以去求最小狀態,就是i、i+1、i+2、……、i+j-1,等於(i + i + j - 1) * j / 2;我們遍歷這其中的狀態,然後都用狀態k減去j * i即可。

 

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[2][105][5051];//第一維代表當前回合,滾動數組優化,
//第二維代表之前進攻次數。5051爲進攻回合數之和(從1加到100最多5050)
ll a[105],b[105],c[105],n,t;
int main()
{
    cin>>t;
    while(t--)
    {
        cin>>n;
        ll ans=0;
        memset(dp,0,sizeof dp);
        for(int i=1; i<=n; i++)
            cin>>a[i]>>b[i]>>c[i];
        dp[n&1][1][n]=a[n];


        for(int i=n-1; i>=1; i--)  ///回合數
        {
            for(int j=n-i; j>=1; j--) ///攻擊次數
            {
              int l=(i+i+j-1)*j/2,r=(n+n-j+1)*j/2;
              for(int k=r;k>=l;k--) ///攻擊次數編號的sum
			  {
			  	dp[i&1][j+1][k+i]=max(dp[i&1][j+1][k+i],dp[(i+1)&1][j][k]+a[i]);
			  	dp[i&1][j][k]=max(dp[i&1][j][k],dp[(i+1)&1][j][k]+j*c[i]);
			  	dp[i&1][j][k]=max(dp[i&1][j][k],dp[(i+1)&1][j][k]+(k-j*i)*b[i]);
			  }
            }
        }
        for(int k=1; k<=n; k++)
            for(int j=1; j<=5050; j++)
                ans=max(ans,dp[1][k][j]);
        cout<<ans<<endl;
        
    }
    return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章