“科林明伦杯”哈尔滨理工大学第七届程序设计团队赛 I.Aggie’s Tasks(带权的LIS)

本文介绍了一个算法问题,旨在解决角色Aggie如何从一系列具有不同难度和利润的任务中选择以获得最大收益。输入包括任务数量、每个任务的难度和预期利润,通过特定算法计算出Aggie可以获得的最大利润。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description

Aggie is faced with a sequence of tasks, each of which with a difficulty value di and an expected profit pi. For each task, Aggie must decide whether or not to complete it. As Aggie doesn’t want to waste her time on easy tasks, once she takes a task with a difficulty di, she won’t take any task whose difficulty value is less than or equal to di.

Now Aggie needs to know the largest profits that she may gain.

Input

The first line consists of one positive integer t (t  10), which denotes the number of test cases.

For each test case, the first line consists one positive integer n (n  100000), which denotes the number of tasks. The second line consists of n positive integers, d1, d2, …, dn (di  100000), which is the difficulty value of each task. The third line consists of n positive integers, p1, p2, …, pn (pi  100), which is the profit that each task may bring to Aggie.

Output

For each test case, output a single number which is the largest profits that Aggie may gain.

Sample Input

1

5

3 4 5 1 2

1 1 1 2 2

Sample Output

4

样例dp数组中存的东西   

3

3 4

3 4 5

1 1  3

1 1  2 2

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#define eps 1e-8
#define ll long long
const int inf = 0x3f3f3f3f;
const long long mod=1e9+7;
const int N=100000+20;
using namespace std;
int t,n;
int a[N];
int b[N];
int dp[100*N];
using namespace std;
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        memset(a,0,sizeof(a));
        memset(dp,inf,sizeof(dp));
        scanf("%d",&n);
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        for(int i=0;i<n;i++)
            scanf("%d",&b[i]);
        int len=0;//最大权值
        for(int i=0;i<n;i++)
        {
            int p=lower_bound(dp,dp+len,a[i])-dp;;
            for(int j=p;j<p+b[i];j++)
            {
                dp[j]=a[i];
                if(j==len) len++;
            }
        }
        printf("%d\n",len);
    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值