#include<bits/stdc++.h>
using namespace std;
int dp[1000007][7][7];
int cnt[1000007];
int main(){
int n,m;
scanf("%d%d",&n,&m);
int x=0;
for(int i=1;i<=n;i++){
scanf("%d",&x);
cnt[x]++;
}
for(int i=1;i<=m;i++)//只考虑前i种数字
for(int j=0;j<=2;j++)//以i开头的三元组{i,i+1,i+2}
for(int k=0;k<=2;k++)//以i-1开头的三元组{i-1,i,i+1}
for(int l=0;l<=2;l++)//以i-2开头的三元组{i-2,i-1,i}
if(cnt[i]-j-k-l>=0)//如果cnt[i]不能大于等于j+k+l的话该情况不成立,不用更新答案
dp[i][j][k]=max(dp[i][j][k],dp[i-1][k][l]+(cnt[i]-j-k-l)/3+j);//大于等于3的话将三元组转化为{i,i,i},在i-1之后添加i即可使k和l转化为j和k同时将答案更新+j(j可能不存在所以最后的答案也是j和k都为零的情况,j和k只是为了状态转移而产生)
printf("%d",dp[m][0][0]);
return 0;
}
相关文章
- 03-31Codeforces Global Round 1D(DP,思维)
- 03-31Codeforces Global Round 14 A~E题解
- 03-31状压dp Codeforces Beta Round #8 C
- 03-31Codeforces Round #336 (Div. 2) C. Chain Reaction set维护dp
- 03-31Codeforces Round #346 (Div. 2) G. Fence Divercity dp
- 03-31【Codeforces Round 1110】Codeforces Global Round 1
- 03-31Codeforces Round #674 (Div. 3) F. Number of Subsequences 题解(dp)
- 03-31Codeforces Round #635 (Div. 2) E——Kaavi and Magic Spell 区间dp
- 03-31Codeforces Global Round B Tape
- 03-31【 Codeforces Global Round 1 B】Tape