HDUOJ 6570 Wave

news/2024/11/28 8:51:15/

HDUOJ 6570 Wave

题目链接

Problem Description

Avin is studying series. A series is called “wave” if the following conditions are satisfied:
1) It contains at least two elements;
2) All elements at odd positions are the same;
3) All elements at even positions are the same;
4) Elements at odd positions are NOT the same as the elements at even positions.
You are given a series with length n. Avin asks you to find the longest “wave” subseries. A subseries is a subsequence of a series.

Input

The first line contains two numbers n, c (1 ≤ n ≤ 100, 000, 1 ≤ c ≤ 100). The second line contains n integers whose range is [1, c], which represents the series. It is guaranteed that there is always a “wave” subseries.

Output

Print the length of the longest “wave” subseries.

Sample Input

5 3
1 2 1 3 2

Sample Output

4

简单 DP,设 d p [ i ] [ j ] dp[i][j] dp[i][j] 是以 j j j 结尾, i i i 为结尾前一个数字的最长合法 wave,则有状态转移方程:
d p [ i ] [ j ] = d p [ j ] [ i ] + 1 dp[i][j]=dp[j][i]+1 dp[i][j]=dp[j][i]+1
注意一个坑点,答案必须要加换行,AC代码如下:

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,c,ans=1,dp[105][105],a[N];
int main(){scanf("%d%d",&n,&c);for(int i=1;i<=n;i++) scanf("%d",&a[i]);for(int i=1;i<=c;i++){if(a[1]==i){dp[a[1]][i]=0;}else{dp[a[1]][i]=1;}}for(int i=2;i<=n;i++){for(int j=1;j<=c;j++){if(a[i]==j) dp[a[i]][j]=0;else dp[a[i]][j]=dp[j][a[i]]+1;ans=max(ans,dp[a[i]][j]);}}printf("%d\n",ans);
}

http://www.ppmy.cn/news/178024.html

相关文章

「LOJ6570 毛毛虫计数」 - 生成函数

LOJ6570 毛毛虫计数 tags:生成函数,多项式 题意 hsezoi 巨佬 olinr 喜欢 van 毛毛虫&#xff0c;他定义毛毛虫是一棵树&#xff0c;满足树上存在一条树链&#xff0c;使得树上所有点到这条树链的距离最多为 \(1\)。给定 \(n\) \((n\le10^5)\) 。现在请你求出 \(n\) 个点、有标号…

HDU 6570 Wave dp

题意&#xff1a;给出一个长度为n的数列 和一个c 数列的所有数都在c范围内 问&#xff1a; 求一个最长子串 满足下列条件&#xff1a; 1 所有奇数位置的数相等 2 所有偶数位置的数相等 3 偶数位置和奇数位置的数不相等 比赛的时候枚举c 然后二分查找n o( c^2 logn ) 78…

D - Wave HDU - 6570

暴力求解 Avin is studying series. A series is called “wave” if the following conditions are satisfied: It contains at least two elements;All elements at odd positions are the same;All elements at even positions are the same;Elements at odd positions are…

GPT(4kb硬盘) 单硬盘装变色龙、GA-H61MA-D2V、ALC887-VD、HD6570成功驱动经验(转)

GPT(4kb硬盘) 单硬盘装变色龙、GA-H61MA-D2V、ALC887-VD、HD6570成功驱动经验 2012-08-21 11:32:17 分类&#xff1a; 系统运维 终于用上黑苹果了&#xff0c;所以决定把这近一个月付出辛劳总结归纳一下&#xff0c;以后也记得操作步骤。基础的就不会详细写&#xff0c;要注意或…

MT6570_MT6580参考设计资料介绍

MT6570_MT6580参考设计资料介绍&#xff1a; MT6570_MT6580 Introduction ▪ GPIO and IO application ▪ System dependent design ▪ Power introduction Function design notice ▪ SIM design note (3/4-SIM application) ▪ NAND flash design note ▪ SD/eMMC design not…

HDU - 6570

题目链接&#xff1a;HDU - 6570 暴力的话就是枚举两种颜色&#xff0c;然后暴力求。因为不可能每一种情况都跑满&#xff0c;均摊下来感觉复杂度是&#xff1a;O(ccsqrt(n))。 事实上我们可以O(n*c)dp&#xff0c;令dp[i][j][k] 为&#xff1a;第i项为k&#xff0c;前面的一个…

AMD显卡更新UEFI GOP

一、简介 很多老版本显卡vBIOS仅支持leagcy&#xff0c;所以在UEFI版本的BIOS下不能显示&#xff0c;本文以HD6570其中一款显卡进行操作。 二、操作步骤 2.1 操作环境 windows操作系统GPU-Z 下载地址NV或者AMD显卡BIOS的刷新工具NVFlash或者ATIFlash下载地址制作给显卡BIOS…

MT6572/MT6570芯片资料介绍,MT6572+MT6570处理器

MT6572处理器&#xff1a; 联发科MT6572 可在不损电池使用时间的情况下&#xff0c;为入门级智能型手机提供双核心效能表现。它配备节能的双核心ARM Cortex-A7 处理器&#xff0c;并采用优化了成本效益的系统级设计&#xff0c;简化了产品研发工序&#xff0c;从而降低生产成本…