Give life a little publicity.🍺|

Mr_Azz

园龄:2年1个月粉丝:0关注:2

📂题解
🔖题解
2024-05-29 21:50阅读: 7评论: 0推荐: 0

P10236 [yLCPC2024] D. 排卡

Question 问题 P10236 [yLCPC2024] D. 排卡

题目大意:给定长度为 n(2n1000) 的序列 a,每次可以从头或尾选一个数放到序列 b(选后删除),求i=1n1bibi+1 的最大值。(我们仅在计算 bibi+1 的时候将得分对 998244353 取模)。

Analysis 分析

首先思考贪心:(错解)

第一个从最左边或最右边拿,然后贪心第二个从最左边还是最右边使得 b1b2 最大,一直这样贪心下去。很明显是错的。但很明显连样例的过不了,正确性显然不存在。

观察到 n 的范围较小,发现想复杂了,直接暴力区间 DP 即可。

Solution

定义 fl,r,(0,1) 为区间 [l,r] 最后弹掉的是最左边的(0)还是最右边的(1)。

转移方程非常好写:

fl,r,0=max{fl+1,r,0+alal+1,fl+1,r,1+alar}fl,r,1=max{fl,r1,0+aral,fl,r1,1+arar1}

对于 fl,r,0 的转移进行一个详细的讲述,fl,r,1 同理。

它只能从 [l+1,r] 转移而来,因为他最后踢掉的是最左边的。所以要么是 fl+1,r,0+alal+1 要么就是 fl+1,r,1+alar.

Code 代码

signed main(){
	read(T);
	while(T--){
		read(n);
		for(rint i=1;i<=n;i++) read(a[i]);
		for(rint i=1;i<=n;i++) for(rint j=1;j<=n;j++) f[i,j,0]=f[i,j,1]=0;
		for(rint len=2;len<=n;len++){
			for(rint l=1;l<=(n-len+1);l++){
				int r=l+len-1;
				f_{l,r,0}=max({f_{l,r,0},f[l+1,r,0]+power(a[l],a[l+1]),f[l+1,r,1]+power(a[l],a[r])});
				f_{l,r,1}=max({f_{l,r,1},f[l,r-1,0]+power(a[r],a[l]),f[l,r-1,1]+power(a[r],a[r-1])});
			}
		}
		printf("%lld\n",max(f[1,n,0],f[1,n,1]));
	}
    return 0;
}

本文作者:Mr-Az

本文链接:https://www.cnblogs.com/Mr-Az/p/18221175/Luogu-P10236

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Mr_Azz  阅读(7)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 使一颗心免于哀伤 知更鸟
使一颗心免于哀伤 - 知更鸟
00:00 / 00:00
An audio error has occurred.

作词 : 黑金雨

作曲 : 王可鑫 Eli.W (HOYO-MiX)

编曲 Arranger : 王可鑫 Eli.W (HOYO-MiX)

制作人 Producer : 王可鑫 Eli.W (HOYO-MiX)

Birds are born with no shackles

Then what fetters my fate?

Blown away, the white petals

Leave me trapped in the cage.

The endless isolation

Can't wear down my illusion

Someday, I’ll make a dream unchained

Let my heart bravely spread the wings

Soaring past the night

To trace the bright moonlight

Let the clouds heal me of the stings

Gently wipe the sorrow off my life

I dream

What is meant by “miracle”,

What is meant by “miracle”,

A word outside my days?

Once again, repeat warbles

But how could I escape?

No further hesitation

On those unanswered questions

So now, I’ll make a dream unchained

Let my heart bravely spread the wings

Soaring past the night

To trace the bright moonlight

Let the clouds heal me of the stings

Gently wipe the sorrow off my life

I dream

Let my heart bravely spread the wings

Soaring past the night

To trace the bright moonlight

Let the clouds heal me of the stings

Gently wipe the sorrow off my life

I dream

I dream

人声 Vocal Artist:Chevy

人声 Vocal Artist:Chevy

木吉他 Acoustic Guitar:赵新博

电吉他 Electric Guitar:赵新博

架子鼓 Drums:眭逸凡Patrick

乐队 Orchestra:国际首席爱乐乐团 International Master Philharmonic Orchestra

人声录音棚 Vocal Recording Studio:The Hideout Recording Studio

人声录音师 Vocal Recording Engineer:Luis Pacheco

乐器录音棚 Instrumental Recording Studio:升赫录音棚Soundhub Studio/九紫天诚录音棚 SKY FIRE STUDIO

乐器录音师 Instrumental Recording Engineer:Kevin刘瀚文@Soundhub Studios/董方昱

混音师 Mixing Engineer:宫奇Gon (HOYO-MiX)

母带制作 Mastering Engineer:宫奇Gon (HOYO-MiX)

出品 Produced by:HOYO-MiX