当前位置:网站首页>Codeforces Round #804 (Div. 2) D. Almost Triple Deletions time limit per test2 seconds (dp好题)
Codeforces Round #804 (Div. 2) D. Almost Triple Deletions time limit per test2 seconds (dp好题)
2022-07-15 12:48:00 【NONE-C】
题目大意
给定一个长度为n的数组,其中可以通过一个操作使得相邻的两个不同的数移除序列,求经过任意次操作后,最终该序列最大能有多少个相同的数剩余。
题目思路
赛场上拿到这道题,想到了以下几点:
对于一段序列,只有当该段序列中出现最多次数的数的次数小于整体一半,那么该段数便可以消去。
于是赛场上便开始对这道题开始疯狂贪心。
在快结束时,想到 n 2 n^2 n2可以去枚举i,j之间的消去性然后转移,到此比赛也结束了。
赛后看了大佬的代码,确实,就是将以上两点结合起来,就可以dp了。
为了判断1,我们只需要在第二重dp时,倒着扫,然后记录最大出现次数即可。
由此而看该题的模型还是十分简单的。
代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
#define int long long
int a[104][104];
int jc[maxn];
void solve()
{
int n;
cin>>n;
vector<int>dp(n+2,-maxn);
dp[0]=0;
vector<int>a(n+3);
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n+1;i++)
{
vector<int>vis(n+1);
int mx=0;
for(int j=i-1;j>=0;j--)
{
if((a[i]==a[j]||i==n+1||j==0)&&(i-j)%2==1&&mx*2<=i-j-1)dp[i]=max(dp[j]+1,dp[i]);
mx=max(mx,++vis[a[j]]);
}
//cout<<i<<" "<<dp[i]<<'\n';
}
cout<<dp[n+1]-1<<'\n';
}
signed main()
{
ios::sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--)solve();
return 0;
}
边栏推荐
- Prospect of distributed database technology
- 二叉树上的相等子树
- leetcode 605. Can place flowers planting problem (simple)
- Flutter 中的 offstage
- torch. Max () and numpy Discrimination of max () use
- 51nod 1102 rectangle with the largest area
- 朱松纯团队最新研究:机器人可与人类“推心置腹”!还说下一步要造“AI大白”...
- [200 opencv routines] 230 LBP statistical histogram of feature description
- Talking about some features of improving work efficiency supported by slack channel
- Zabbix proxy主動模式的實現
猜你喜欢

Slow SQL analysis and optimization

想成为精英级开发者?请逼自己养成这10个习惯

Unp learning notes - Chapter 2 transport layer

MES管理系统的四个功能,高效提升工厂数字化

Index in MySQL
![[visdom drawing] summary of visdom drawing in deep learning](/img/1d/534eb0d1c0f7108d8cb959bd66c65d.png)
[visdom drawing] summary of visdom drawing in deep learning

Trends in Plant Science | 向改善生态的植物-微生物组互作的方向育种

Teach people to fish - see a field on the sap mm material display interface, how to find which field of which database table to store

Flutter中的IndexedStack

四面阿里offer定级P8,2022最新最实用阿里68道高级面试题,助你们面试成功!!
随机推荐
Realizing deep learning framework from zero -- glove
Looking for a big brokerage to open an account? Is it safe to open an account through mobile stock now?
Award winning research | openeuler developer experience research questionnaire
PD-Server GRPC 接口图解
“小白嘴”白山药是哪个县的特色农产品? 蚂蚁新村7月15日答案
std::unique_ The use of PTR as a formal parameter
Clickpaas Ma Jun: model driven low code platform practice
torch. Max () and numpy Discrimination of max () use
C# 使用ToolTip控件实现气泡提示
Lesson 2 WiFi experiment of hi3861 -api-1
AI简报-模型集成 SAM 和SWA
中国人力资源数字化生态图谱-灵活用工市场
The world's first commercial cryptographic chip against quantum attack | Muchuang
Data transmission: Practice of batch extraction of isomorphic and heterogeneous IP data sources
Tencent T4 architects give you a "glimpse" of the main technical challenges and solutions of large website architecture
想成为精英级开发者?请逼自己养成这10个习惯
bitmap签到
抢占新赛道,和数集团大力布局“元宇宙”产业
【visdom绘图】深度学习中Visdom绘图的总结
McKinsey: in the next decade, the top ten technology trends will affect investment and research direction
