牛客多校第六场——Upgrading Technology

题目描述
Rowlet is playing a very popular game in the pokemon world. Recently, he has encountered a problem and wants to ask for your help.

In this game, there is a technology tree system. There are n kinds of technology in this game, each of them has m levels numbered from 1 to m. In the beginning, all technologies have no level (regard as level 0). When the i-th technology is at the (j - 1)-th level, the player can pay c_{i j}c
ij

pokedollars (currency used in this game) to upgrade this technology into the j-th level. However, sometimes upgrading is so easy that the cost might be negative, which implies the player may gain profit from upgrading technologies.

Moreover, if all technologies have been upgraded to level j, the player will gain an additional profit of d_{j}d
j

pokedollars. However, sometimes too many technologies of the same level might be confusing, hence the profit can be negative as well.

Rowlet wants to determine the optimal strategy that can bring him the most pokedollars. Help him to find the maximum gain. Note that Rowlet may upgrade nothing, and in that case, the profit is zero.
输入描述:
There are multiple test cases. The first line contains an integer T (1 \leq T \leq 101≤T≤10), indicating the number of test cases. Test cases are given in the following.

For each test case, the first line contains two integers n, m (1 \leq n, m \leq 10001≤n,m≤1000), representing the number of technologies and the number of levels respectively.

The i-th of the next n lines contains m integers, where the j-th number is c_{i j}c
ij

(-10^{9} \leq c_{i j} \leq 10^{9}−10
9
≤c
ij

≤10
9
).

The last line contains m integers, where the j-th number is d_{j}d
j

(-10^{9} \leq d_{j} \leq 10^{9}−10
9
≤d
j

≤10
9
).

We ensure that the sum of n \cdot mn⋅m in all test cases is at most 2 \times 10^{6}2×10
6
.
输出描述:
For each test case, output “Case #x: y” in one line (without quotes), where x indicates the case number starting from 1, and y denotes the answer(in pokedollars) to this test case.
示例1
输入

复制
2
2 2
1 2
2 -1
4 1
3 3
1 2 3
1 2 3
1 2 3
6 7 8
输出

复制
Case #1: 2
Case #2: 4
说明

In the first example, Rowlet can upgrade the first technology to level 1 and the second technology to level 2, which costs 1 + 2 - 1 = 2 pokedollars, but Rowlet can get 4 pokedollars as the bonus of upgrading all technologies to level 1, so the answer is 4 - 2 = 2 pokedollars.

In the second example, Rowlet can upgrade all technologies to level 2, which costs 1\times3 + 2\times3=91×3+2×3=9 pokedollars, but Rowlet can get 6 pokedollars as the bonus of upgrading all technologies to level 1 and 7 pokedollars as the bonus of upgrading all technologies to level 2, so the answer is 6 + 7 - 9 = 4 pokedollars.

题面:自己看
思路:维护前缀和,纵向和,定义能吃到第n等级的奖励然后看看能不能多吃点利润;
比较最大值;

#include<iostream>
#include <iomanip>
#include<deque>
#include<map>
#include<cstring>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long ll;
const int maxn = 2005;
ll a[maxn][maxn],d[maxn],n,m,maxc[maxn][maxn];
int main(void)
{
    int t,cas=0;
    cin>>t;
    while(t--){
        cin>>n>>m;
        memset(a,0,sizeof(a));
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                cin>>a[i][j];
                a[i][j]*=-1;
               }  
        }
        d[0]=0;
        for(int i=1;i<=m;i++)cin>>d[i];
         
        for(int i=0;i<maxn;i++)
            for(int j=0;j<maxn;j++){
                maxc[i][j]=-INF;
            }
             
        for(int i=1;i<=n;i++){
            for(int j=2;j<=m;j++)
                a[i][j]+=a[i][j-1];
        }
         
        for(int i=1;i<=n;i++){
            maxc[i][m]=a[i][m];
            for(int j=m-1;j>=0;j--){
                maxc[i][j]=max(a[i][j],maxc[i][j+1]);
            }
        }
         
        for(int i=2;i<=m;i++)d[i]+=d[i-1];
         
        ll ans=0;
        for(int i=0;i<=m; i++){
            ll temp=d[i];
            ll sum=0;
            for(int j=1;j<=n;j++)sum+=maxc[j][i];
            for(int j=1;j<=n;j++){
                ll tt=sum-maxc[j][i]+a[j][i]+temp;
                ans=max(ans,tt);
            }
        }
        printf("Case #%d: %lld\n",++cas,ans);      
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值