The 2022 ICPC Asia Regionals Online Contest (II) B
B : Non-decreasing Array
You are given a non-decreasing array of integers a1,a2,…,an. In one operation, when the current length of the array is m:
- Firstly you can choose an index i(1<i<m) and delete ai (m decrease 1) or you can do nothing,
- Secondly you can choose an index i(1<i<m) and change ai to any integer.
You should ensure that the array is non-decreasing after every delete or change.
Now you want to know that after operating k(1≤k≤n) times, when the current length of the array is m, what is the maximum value of ∑(i=2-m)(ai−ai_1)^2.
You need to answer for each k(1≤k≤n), different queries are independent of each other.
输入格式:
The first line contains one integer n(3≤n≤100).
The second line contains n integers a1,a2,...,an(−10^9≤ai≤10^9).
输出格式:
Output n lines, each of which contains a single integer—the i-th number is for the answer of k=i.
输入样例:
5 1 2 3 4 5
输出样例:
10 16 16 16 16
代码长度限制
16 KB
时间限制
400 ms
内存限制
dp[i][k] 为前[1-i]中删除k个数,且a[1],a[i]不删除的最大权值
1次操作对应两次删除
#include<bits/stdc++.h>
using namespace std;
typedef double db;
#define int long long
const int N=110;
int a[N],n;
int dp[N][N];
int dfs(int id,int k)
{if (dp[id][k]!=-1)return dp[id][k];int mx=0;for(int i=1;i<id;i++){//del[i+1,id-1]int cnt=(id-1)-(i+1)+1;//删除的个数if (cnt>k)continue;mx=max(mx,dfs(i,k-cnt)+(a[id]-a[i])*(a[id]-a[i]));}return dp[id][k]=mx;
}
signed main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cin>>n;for(int i=1; i<=n; i++){cin>>a[i];}memset(dp,-1,sizeof dp);for(int i=1; i<=n; i++){cout<<dfs(n,min(n-2,i*2))<<"\n";}return 0;
}
The 2022 ICPC Asia Regionals Online Contest (II) B相关推荐
- The 2022 ICPC Asia Regionals Online Contest (II) A、B、E、F、G、J、L
文章目录 A-Yet Another Remainder 题目 题解 B-Non-decreasing Array 题目 题解 E-An Interesting Sequence 题目 题解 F-In ...
- The 2022 ICPC Asia Regionals Online Contest (II) 2022ICPC第二场网络赛 ABEFGJKL题解
文章目录 A Yet Another Remainder[费马小定理] B Non-decreasing Array[线性DP] E An Interesting Sequence[签到] F Inf ...
- The 2022 ICPC Asia Regionals Online Contest (II) J
J:A Game about Increasing Sequences 不是特别会博弈,只能说一下大概意思 Alice and Bob like playing games. The game is ...
- The 2022 ICPC Asia Regionals Online Contest (I)
D题 The 2022 ICPC Asia Regionals Online Contest (I) 03:14:13 H Step Debugging 作者 pku 单位 北京大学 Rikka is ...
- 2021 ICPC Asia Regionals Online Contest (II) Problem G. Limit
The 2021 ICPC Asia Regionals Online Contest (II) Problem G. Limit 在欧教的指导下,复习了下高数知识,写下了这题的题解- 做这道题之前, ...
- 【ICPC 2021网络赛2】The 2021 ICPC Asia Regionals Online Contest (II)签到题5题
M. Addition 题意: 给出n,接下来三行,每行n位二进制数,分别表示符号sgn{-1,1}和a{0,1}, b{0,1}. 令c=a+b(a和sgn每位相乘得到数a),最后将c拆成每一位输出 ...
- 2021ICPC网络赛第二场The 2021 ICPC Asia Regionals Online Contest (II) 【L Euler Function】
分析: 根据欧拉函数的那个性质 if(p是质数){if(i % p == 0) f[i * p] = f[i] * p;else f[i * p] = f[i] * (p - 1);} 每次区间乘的那 ...
- The 2022 ICPC Asia Regionals Online Contest - A 01 Sequence
01 Sequence 题目 Given a binary cyclic sequence S of length n, whose elements are either 0 or 1, you c ...
- The 2021 ICPC Asia Regionals Online Contest (II)
比赛链接 A. Sort 暴力 k=1k=1k=1 检查数组是否有序: k=2k=2k=2 相当于再环上找个起点使得数组有序,直接判断: k≥3k\ge 3k≥3 考虑插入排序,每次暴力找到第 iii ...
最新文章
- 关于数据库性能优化小经验
- hive 0.11 mysql_Hive的升级(0.8.0到0.11.0)
- Polycarp Training
- 服务器可以装两个系统吗,云服务器可以装多个系统吗
- weblogic双机热备部署linux,WebLogic应用在集群环境下的一些基本知识【转载】
- CSS3开发总结(圆角、盒阴影、边界图片)
- 【转】解决win7下重装winXP 系统启动选择菜单消失 问题
- 获取进程的信息 linux,如何获取进程信息
- 13、TCP Socket与UDP Socket
- 2022超级好看动态视频官网HTML源码
- ubuntu17.04 UHD 驱动出错
- java jbutton 禁用_java – 在后台作业时禁用JButton,以避免多次单击
- xml格式转json
- 如何用MATLAB读取大文本文件
- Python3对Excel表格操作(写入、追加)
- CTWAP下程序崩溃
- 百度apollo自动驾驶planning代码学习-Apollo\modules\planning\constraint_checker\CollisionChecker类代码详解
- Kafka Spout Offset存储在Zookeeper
- 使用Java语言编写一个五子棋UI界面并实现网络对战功能(非局域网)
- 监控里的主码流和子码流是什么意思
热门文章
- C#做的配套C做的SNIFFER(C#)--C#简单而实用
- 【工具mdnice】Markdown在线工具-支持知乎、微信排版
- pgadmin数据输出不存在了?
- ajax判断邮箱是否重复,帝国cms插件ajax判断用户名和邮箱是否存在
- 【数学】方差/标准差的各种估计辨析
- 高中信息技术知识点归纳总结
- ISV是Independent Software Vendors 的英文缩写,意为“独立软件开发商”
- 红月服务器修改技能范围,天涯红月常见问题解答表(不断更新)--天涯红月(中文)官方网站-红月十年浩劫风云再起...
- 如何安装小企鹅输入法
- 管家婆服装.NET II TOP 系列,安装过程中提示“silverlight/Sys未定义”错误,解决方案