Codeforces Global Round 1D(DP,思维)
#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;
}
Codeforces Global Round 1D(DP,思维)的更多相关文章
- CodeForces Global Round 1
CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...
- Codeforces Global Round 1 - D. Jongmah(动态规划)
Problem Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...
- Codeforces Global Round 1 (A-E题解)
Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...
- Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)
Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...
- Codeforces Global Round 2 题解
Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...
- Codeforces Global Round 3
Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...
- 【手抖康复训练1 】Codeforces Global Round 6
[手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...
- Codeforces Global Round 11 个人题解(B题)
Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...
- Codeforces Global Round 2 E. Pavel and Triangles(思维+DP)
题目链接:https://codeforces.com/contest/1119/problem/E 题意:有n种长度的棍子,有a_i根2^i长度的棍子,问最多可以组成多少个三角形 题解:dp[i]表 ...
随机推荐
- java中Swing编程再度练习篇
总结: 注意理解frame的层级关系 package com.da; //添加背景图片 //我只实现了插入图片.但并没有实现是背景图片 import javax.swing.JFrame; impor ...
- Swing编程中为什么对Panel设置了位置后,它的lable位置也跟这变了呢?
总结: package com.da; //这里我不明白,我对每一个Panle里的按钮设置了位置BorderLayout.SOUTH.可是为什么Lable的位置和它一样同步设置了呢? //做一个界面 ...
- java代码I/O类
总结:流类无法理解啊—————— package com.aini; import java.io.*; //流类 //使用FileInputStream读取文件信息 public class ffg ...
- mycat sequence
数据库方式原理在数据库中建立一张表,存放sequence名称(name),sequence当前值(current_value),步长(increment int类型每次读取多少个sequence,假设 ...
- 简单的触发黑名单阻断演示 control+c
#include "stdafx.h"#include <signal.h>#include <windows.h> #include <iostre ...
- python paramiko 调试
#!/usr/bin/env python #-*- encoding:utf-8 -*- import paramiko transport = paramiko.Transport(('10.34 ...
- C#改变LInqToSQL的引用地址,读取config的数据库字符串
C#改变LInqToSQL的引用地址,读取config的数据库字符串修改Properties 下 Settings.Settings 下 Settings.Designer.cs 下 return ( ...
- Navicat for Oracle中如何使用外键
转自:https://blog.csdn.net/weixin_39183543/article/details/80555104 1. 外键名最后保存的时候自动生成: 2. 参考模式自动生成: 3. ...
- LNMP 1.6 常见的502问题解决
在nginx上跑discuz,先修改配置文件 cd /usr/local/nginx/conf/vhosts/ vim test.conf server { listen ; server_name ...
- Developer tools
20. Developer tools Spring Boot includes an additional set of tools that can make the application de ...