首页 > 其他分享 >[CF1768F]Wonderful Jump

[CF1768F]Wonderful Jump

时间:2023-09-04 22:56:55浏览次数:37  
标签:min int sqrt Jump leq Wonderful MAXN CF1768F dp

Wonderful Jump
题目看错了,以为能往回跳......
暴力转移式

\[dp_i=min(dp_i,dp_j+\min_{k=j}^ia_k\times(i-j)^2) \]

你会发现这个没啥单调性,不好用数据结构维护。
所以考虑发掘性质,设 \(x=\min_{k=j}^ia_k\),那么一个宽松的上界是 \((i-j)\leq\lfloor\frac{n}{x}\rfloor\)
对于 \(x\geq\sqrt n\),可以得到\((i-j)\leq\sqrt n\),直接 \(\Omicron(n\sqrt n)\) 枚举,这是第一种转移。
讨论 \((i-j)>\sqrt n\)
不难发现 \((i-j)^2\geq(k-j)^2+(i-k)^2\),这说明当从 j 跳到 i 最优时 \(x=a_j\) 或 \(x=a_i\)。
1.\(x=a_j\)
这时 \(a_j\leq\sqrt n\),否则一定不会比第一种转移优,所以记录 \(a_k\leq\sqrt n\) 的最后一个位置 k。
为什么我们不用之前与 \(a_k\) 值相同的位置 \(k1\),讨论一下 k1 和 k 之间的值就会发现这样最优。复杂度 \(\Omicron(n\sqrt n)\)。
2.\(x=a_i\)
不难发现此时 \(a_i\leq\sqrt n\) 那么往前枚举 j 直到 \(a_j\leq a_i\),复杂度 \(\Omicron(n\sqrt n)\)。
以上三种不重不漏。

#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
#define ll long long
const int MAXN=4e5+5;
const ll INF=1e18;
int n,B,a[MAXN],wz[MAXN],BB;
ll dp[MAXN]; 
int main(){
	scanf("%d",&n);B=sqrt(n);BB=B+4;for(int i=1;i<=n;i++) scanf("%d",&a[i]),dp[i]=INF;dp[1]=0;
	wz[a[1]]=1;
	for(int i=2;i<=n;i++){
		int mi=a[i];
		for(int j=i-1;j>=max(1,i-BB+1);j--){
			mi=min(mi,a[j]);dp[i]=min(dp[i],dp[j]+1ll*mi*(i-j)*(i-j));
		}	
		for(int j=1;j<=B;j++){
			if(!wz[j]) continue;
			dp[i]=min(dp[i],dp[wz[j]]+1ll*j*(i-wz[j])*(i-wz[j]));
		}
		wz[a[i]]=i;
		if(a[i]<=B){
			for(int j=i-1;j>=1;j--){
				if(a[j]<=a[i]) break;
				dp[i]=min(dp[i],dp[j]+1ll*a[i]*(i-j)*(i-j));
			}
		}
	}
	for(int i=1;i<=n;i++) printf("%lld ",dp[i]);return 0;
} 

标签:min,int,sqrt,Jump,leq,Wonderful,MAXN,CF1768F,dp
From: https://www.cnblogs.com/StranGePants/p/17678143.html

相关文章

  • linux-jumpserver
    1、关闭防火墙systemctlstopfirewalldsystemctldisablefirewalld修改/etc/selinux/config文件将SELINUX=enforcing改为SELINUX=disabled  2、同步时钟centos7:dateyuminstallntpdate-ytimedatectlset-timezoneAsia/Shanghaintpdatentp1.aliyun.comsystemctlen......
  • [LeetCode][55]jump-game
    ContentYouaregivenanintegerarraynums.Youareinitiallypositionedatthearray'sfirstindex,andeachelementinthearrayrepresentsyourmaximumjumplengthatthatposition.Returntrueifyoucanreachthelastindex,orfalseotherwise.......
  • LeetCode[55]JumpGame
    ContentYouaregivenanintegerarraynums.Youareinitiallypositionedatthearray'sfirstindex,andeachelementinthearrayrepresentsyourmaximumjumplengthatthatposition.Returntrueifyoucanreachthelastindex,orfalseotherwise.......
  • No_55_JumpGame
    ContentYouaregivenanintegerarraynums.Youareinitiallypositionedatthearray'sfirstindex,andeachelementinthearrayrepresentsyourmaximumjumplengthatthatposition.Returntrueifyoucanreachthelastindex,orfalseotherwise.......
  • CF1588 FJumping Through the Array
    CF1588FJumpingThroughtheArray题意你有个长度为\(n\)的数组\(a\)和一个长度为\(n\)的排列\(p\),对于每一个\(i\)有一有向边\((i,p_i)\)。有如下三种操作:1lr询问\(\sum_{i=l}^ra_i\)。2vx将所有\(v\)能到达的节点所对应编号的值加\(x\)。3x......
  • wonderful-sql Task06
    SectionA练习一:各部门工资最高的员工(难度:中等)创建Employee表,包含所有员工信息,每个员工有其对应的Id,salary和departmentId。CREATETABLE`Employee`( `Id`INTPRIMARYKEY, `Name`VARCHAR(20), `Salary`INT, `DepartmentId`INT);INSERTINTO`E......
  • wonderful-sql Task05
    练习题1请说出针对本章中使用的product(商品)表执行如下SELECT语句所能得到的结果。SELECTproduct_id,product_name,sale_price,MAX(sale_price)OVER(ORDERBYproduct_id)ASCurrent_max_priceFROMproduct;2继续使用product表,计算出按照......
  • jumpserver 基于docker ins
    jumpeserver的安装部署1.随机生成加密密钥if["$SECRET_KEY"=""];thenSECRET_KEY=`cat/dev/urandom|tr-dcA-Za-z0-9|head-c50`;echo"SECRET_KEY=$SECRET_KEY">>~/.bashrc;echo$SECRET_KEY;elseecho$SECRET_KEY;fiif[&q......
  • wonderful-sql Task02
    练习题1.创建出满足下述三个条件的视图(视图名称为ViewPractice5_1)。使用product(商品)表作为参照表,假设表中包含初始状态的8行数据。条件1:销售单价大于等于1000日元。条件2:登记日期是2009年9月20日。条件3:包含商品名称、销售单价和登记日期三列。CREATEVIEW......
  • wonderful-sql Task02
    练习题1.编写一条SQL语句,从product(商品)表中选取出“登记日期(regist_date)在2009年4月28日之后”的商品,查询结果要包含productname和regist_date两列。SELECT product_name, regist_dateFROM productWHERE regist_date<'2009-04-28';2.请说出对product......