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]表 ...
随机推荐
- mysql的备份恢复等操作
备份数据库 shell> mysqldump -h host -u root -p dbname >dbname_backup.sql 恢复数据库 shell> mysqladmin ...
- Azure的CentOS上安装LIS (Linux Integration Service)
Azure上虚拟化技术都是采用的Hyper-v,每台Linux虚拟机都安装了LIS(Linux Integration Service).LIS的功能是为VM提供各种虚拟设备的驱动.所以LIS直接影响 ...
- POJ2777(线段树涂色问题)
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 42828 Accepted: 12973 Des ...
- HDU4039(map应用)
The Social Network Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)T ...
- cassandra安装配置
准备运行环境1.1 cassandra可以安装在windows和linux下,本例子安装在centos6.7的环境下.1.2 关闭防火墙.或者开放9042(默认的CQL本地服务端口).9160(默认的 ...
- iOS利用SDWebImage图片下载缓存
一.我们先来了解一下SDWebImage的使用: 1.导入框架,引入头文件: #import "UIImageView+WebCache.h" 也可以直接使用CocoaPods来引 ...
- Rails的静态资源管理(五)—— 自定义 Asset Pipeline
官方文档:http://guides.ruby-china.org/asset_pipeline.html http://guides.rubyonrails.org/asset_pipeline.h ...
- PowerDesigner CDM中取消默认不能存在同名主键的方法
This data item is already used in a primary identifier.Normalization rules prevent ... 处理的方法为: 菜单栏上的 ...
- 问题:Server.MapPath;结果:Server.MapPath的命名空间
习惯用Access的朋友都知道:ADO.NET链接Access数据库经常这么写:strcon="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&q ...
- RandomForestClassifier(随机森林检测每个特征的重要性及每个样例属于哪个类的概率)
#In the next recipe, we'll look at how to tune the random forest classifier. #Let's start by importi ...