zoukankan      html  css  js  c++  java
  • CodeForces 1321B. Journey Planning

    传送门

    题意

    给数列 (a_1,a_2,...,a_n),要求找出子数列 (a_{k_1},a_{k_2},...,a_{k_m}),使子数列和最大,其中 (a_{k_i}-a_{k_{i-1}}=k_i-k_{i-1}),求最大和。

    题解

    这道题不会做,所有心态崩了看 Navi 暴捶 G2 去了。
    其实 (a_{k_i}-a_{k_{i-1}}=k_i-k_{i-1}) 微微调整一下就是 (a_{k_i}-k_i=a_{k_{i-1}}-k_{i-1})
    可以发现同一个子数列中,值 (-) 下标相同
    所以记录同一个差值的最大和就是答案了

    代码

    #include <iostream>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <math.h>
    #include <algorithm>
    #include <queue>
    #include <map>
    #define lowbit(x) ((x)&(-x))
    using namespace std;
    typedef long long LL;
    const int MAXN=2e5+10;
    const int MAXM=4e5+10;
    int n,b[MAXN];
    map<int,LL> mp;
    
    int main(){
    	scanf("%d",&n);
    	for(int i=1;i<=n;i++) scanf("%d",&b[i]);
    	LL ans=0;
    	for(int i=1;i<=n;i++) mp[b[i]-i]+=b[i],ans=max(ans,mp[b[i]-i]);
    	printf("%lld
    ",ans);	
    	return 0;
    }
    
  • 相关阅读:
    docker生产——容器通信
    .net core集成JWT(基础)
    JWT基本概念
    MySQL数据更新
    MySQL查询练习2
    C语言程序设计之字符串处理
    MySQL查询练习
    博客文章搬迁
    C语言程序设计之 数组2020-10-28
    Java方法重载浅谈
  • 原文地址:https://www.cnblogs.com/BakaCirno/p/12404536.html
Copyright © 2011-2022 走看看