• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

标题链接:https://www.luogu.com.cn/problem/P5858

: \(dp[j]\):的状态是当\(j)种原料的后锅里有\(i)种原料时的最优值。

阶段: (J \)

第:号决定(DP[J]=\ Max _ { KJ S }(DP[K][J-1]K * A[J]))

边界: \(dp[1][1]=a[1]\)

优化1:

显然,(dp)数组的(I)行的大小只与(i-1)行有关,所以可以通过滚动数组来优化空间复杂度。

优化2:

\(\ max _ { kj s } \ { DP[k][j-1]k * a[j]\ }=\ max _ { kj s } \ { DP[k][j-1]\ } k * a[j]\)

这里,涉及区间的最大值的查询3360。

暴力计算的复杂度为O(n)

其次,我们很容易想到用段树来维护区间的最大值,复杂度可以降低到\(O(logn)\)

其实有一个更高效的方法。我们可以看到查询区间是不断向右移动的,所以我们可以利用查询区间的排序,用一个单调的队列来维持最大值。For \(dp[l_1][j-1]\)和\(dp[l_2][j-1]\),if \(或者它是有效的,所以我们可以维持一个单调递减的队列,其中有下标。这样,我们可以将复杂度降低到(O(1)

下面的代码是3360。

#包含位/标准数据。h

使用命名空间std

#定义ll long long

#定义整数ll

const int maxn=5e3 5

int n,w,s,a[maxn],dp[2][maxn],q[maxn],l,r;

无效求解()

{

DP[0][1]=a[1];

int lastp=0,curp,p;

for(int I=2;I=n;i ) {

curp=(lastp 1) % 2,l=1,r=0,p=1;

for(int j=1;j=I j=w;j ) {

while (p=i - 1 p=j s - 1) {

while(r=l DP[lastp][p]=DP[lastp][q[r]])r-;

q[r]=p;

}

while(q[l]j-1)l;

DP[curp][j]=DP[lastp][q[l]]j * a

}

lastp=curp

}

cout *max_element(dp[(n 1) % 2] 1,DP[(n 1)% 2]w 1);

}

带符号的main()

{

IOs : sync _ with _ stdio(false);

cin.tie(0),cout . tie(0);

cin新南威尔士;

for(int I=1;I=n;CIN a

solve();

返回0;

}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now