Codeforces Global Round 1 - D. Jongmah(动态规划)
Problem Codeforces Global Round 1 - D. Jongmah
Time Limit: 3000 mSec
Problem Description

Input

Output
Print one integer: the maximum number of triples you can form.
Sample Input
10 6
2 3 3 3 4 4 4 5 5 6
Sample Output
3
题解:动态规划,对这种状态定义不熟悉,主要还是没有发现最优方案所具有的性质,其实个人感觉dp往往是在一定的观察的基础上进行的,发现最优结果所必须具有的一些特征,然后利用这种特征减少状态总数,使得dp能够进行。这道题的一个性质就是我们可以让最优结果中对每个i,不会出现三个及三个以上(i, i+1, i+2)型的三元组,因为这样的三元组可以被3个i,3个i+1,3个i+2所替代,而不产生任何影响,这样一来我们就可以对每个i,枚举它所组成的三元组的个数,具体状态定义:
dp[i][j][k],考虑前i种数,(i-1, i, i+1)有j个,(i, i+1, i+2),有k个的最多三元组数
不记录(i-2, i-1, i)的个数是因为在状态转移时用不到,用dp[i][j][k]更行dp[i+1][k][t]即可。转移方程很简单,详见代码。
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 1; i <= (n); i++)
#define sqr(x) ((x) * (x)) const int maxn = + ;
const int maxm = + ;
const int maxs = + ; typedef long long LL;
typedef pair<int, int> pii;
typedef pair<double, double> pdd; const LL unit = 1LL;
const int INF = 0x3f3f3f3f;
const double eps = 1e-;
const double inf = 1e15;
const double pi = acos(-1.0);
const int SIZE = + ;
const LL MOD = ; int n, m;
int a[maxn];
int dp[maxn][][]; int main()
{
ios::sync_with_stdio(false);
cin.tie();
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
cin >> n >> m;
int x;
for (int i = ; i < n; i++)
{
cin >> x;
a[x]++;
}
memset(dp, -INF, sizeof(dp));
dp[][][] = ;
for (int i = ; i <= m; i++)
{
for (int j = ; j < ; j++)
{
for (int k = ; k < ; k++)
{
int lim = a[i + ] - j - k;
if (lim < )
continue;
for (int t = ; t < && t <= lim; t++)
{
dp[i + ][k][t] = max(dp[i + ][k][t], dp[i][j][k] + t + (lim - t) / );
}
}
}
}
cout << dp[m + ][][] << endl;
return ;
}
Codeforces Global Round 1 - D. Jongmah(动态规划)的更多相关文章
- CodeForces Global Round 1
CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...
- 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 Round 1110】Codeforces Global Round 1
Codeforces Round 1110 这场比赛只做了\(A\).\(B\).\(C\),排名\(905\),不好. 主要的问题在\(D\)题上,有\(505\)人做出,但我没做出来. 考虑的时候 ...
- Codeforces Global Round 11【ABCD】
比赛链接:https://codeforces.com/contest/1427 A. Avoiding Zero 题意 将 \(n\) 个数重新排列使得不存在为 \(0\) 的前缀和. 题解 计算正 ...
随机推荐
- 《深入理解Java虚拟机》(一)Java虚拟机发展史
Java虚拟机发展史 1.Sun Classic/Exact VM 1.Sun Classic:世界第一款商用Java虚拟机. 2.Exact VM:准确式GC:虚拟机可以知道内存中的某个位置的数据具 ...
- c# 对html字符串进行编码
/// <summary> /// 对html字符串进行编码 /// </summary> /// <param name="html">htm ...
- c# 封装 Request操作类
/// <summary> /// 判断当前页面是否接收到了Post请求 /// </summary> /// <returns>是否接收到了Post请求</ ...
- WebApi接口传参
目前接口统一使用 [FromBody]Dictionary<string,string> req 来接收. 有时候,需要把从req字典提取多个字段赋值给 model,几个还好,几十个赋值就 ...
- 【Spring】14、SpringMVC拦截器的配置
拦截器: com.zk.interceptors.MyInterceptor 实现了 HandlerInterceptor接口,可以拦截@RequestMapping注解的类和方法 第一种方式 < ...
- Confluence设置MySQL数据库报错:必须使用'READ-COMMITTED'作为默认隔离级别。
解决方案: mysql -u root -p123456 SET GLOBAL tx_isolation='READ-COMMITTED'; mysql数据库创建 1.设置mysql隔离级别 SET ...
- 正则与python的re模块
一.正则表达式的语法 正则表达式使用反斜杠字符('\')来表示特殊的形式或者来允许使用特殊的字符而不要启用它们特殊的含义.这与字符串字面值中相同目的的相同字符的用法冲突:例如,要匹配一个反斜线字面值, ...
- GitHub使用SSHkey进行连接
SSH key的配置基本是我们使用git必备的配置,配置好可以避免频繁的在git push或者git pull的时候输入账号和密码 本来我的SSH key早就配置好了,结果他不起作用了,那就在配置一次 ...
- 转: Laravel 自定义公共函数的引入
来源:Laravel 自定义公共函数的引入 背景习惯了 使用 ThinkPHP 框架,有一个公共方法类在代码编写上会快捷很多,所以有必要在此进行配置一番.测试框架:Laravel 5.5步骤指导1. ...
- Salesforce小知识:在简档中设置Visualforce页面的权限
简档(Profile)中的 Visualforce 页面访问权限 在Salesforce中,对于自定义的简档,可以设置"Visualforce 页面访问"的权限. Visualfo ...