列表

详情


NC22432. Misunderstood … Missing

描述

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 , 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 .
    ·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?

输入描述

The first line contains a single integer , 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 , the number of rounds.
The following n lines contain for . The i-th line among them contains three integers separated by spaces in order.
It is guaranteed that the sum of n in all test cases is at most 100.

输出描述

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

示例1

输入:

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

输出:

6
10
24

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++11(clang++ 3.9) 解法, 执行用时: 75ms, 内存消耗: 9572K, 提交时间: 2020-03-17 13:40:21

#include<cstdio>
#include<cstring>
#include<algorithm>
const int N=105;
int n,a[N],b[N],c[N];
long long f[N*N][N];
int main()
{
	int T;
	for(scanf("%d",&T);T--;)
	{
		scanf("%d",&n);
		int m=n*(n+1)/2;
		memset(f,-1,sizeof(f));
		for(int i=1;i<=n;++i) scanf("%d%d%d",&a[i],&b[i],&c[i]);
		f[n][1]=a[n];
		for(int i=n-1;i;--i)
		for(int j=m;j>=n;--j)
		for(int k=n-i+1;k;--k)
		{
			if(~f[j][k]) f[j][k]+=std::max(1LL*k*c[i],1LL*(j-i*k)*b[i]);
			if(j-i>=n&&k>=2&&~f[j-i][k-1]) f[j][k]=std::max(f[j][k],f[j-i][k-1]+a[i]);
		}
		long long ans=0;
		for(int i=1;i<=m;++i)
		for(int j=1;j<=n;++j)
		ans=std::max(ans,f[i][j]);
		printf("%lld\n",ans);
	}
	return 0;
}

C++14(g++5.4) 解法, 执行用时: 55ms, 内存消耗: 58872K, 提交时间: 2019-01-13 12:30:16

#include<bits/stdc++.h>
using namespace std;
long long dp[101][101][5001];
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int n;
		for(int i=0;i<101;i++)
			for(int j=0;j<5001;j++)
				dp[0][i][j]=0;
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
			long long a,b,c;
			scanf("%lld%lld%lld",&a,&b,&c);
			for(int j=0;j<=n-i+1;j++)
			{
				for(int k=(1+j)*j/2;k<=(1+j)*j/2+(n-i+1-j)*j&&k<=5000;k++)
				{
					dp[i][j][k]=max(dp[i-1][j+1][k+j+1]+a,max(dp[i-1][j][k+j]+k*b,dp[i-1][j][k+j]+j*c));
				}
			}
		}
		printf("%lld\n",dp[n][0][0]);
	}
}

上一题