K Balanced Teams
https://codeforces.com/contest/1133/problem/E
题解:DP
/*
*@Author: STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=5000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
int ans,cnt,flag,temp,sum;
int a[N];
char str;int maxl[N];
int dp[N][N];
int main()
{
#ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout);
#endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){scanf("%d%d",&n,&k);for(int i=1;i<=n;i++){scanf("%d",&a[i]);}sort(a+1,a+n+1);int L=1;int R=1;while(L<=R&&R<=n){if(a[R]-a[L]<=5){maxl[R]=R-L+1;R++;}else{L++;}}for(int i=1;i<=n;i++){dp[1][i]=max(dp[1][i-1],maxl[i]);}if(dp[1][n] + k >= n){cout << n << endl;return 0;}for(int i=2;i<=k;i++){for(int j=1;j<=n;j++){for(int l=1;l<=maxl[j];l++){dp[i][j] = max(dp[i][j-1],max(dp[i][j],dp[i-1][j-l]+l));if(dp[i][j]>=n){cout << n << endl;return 0;}}}}for(int i=1;i<=k;i++){ans=max(dp[i][n],ans);}cout<<ans<<endl;//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif//cout << "Hello world!" << endl;return 0;
}
K Balanced Teams相关推荐
- Codeforces-868C - Qualification Rounds - 思维
链接: http://codeforces.com/contest/868/problem/C 题目: Snark and Philip are preparing the problemset ...
- GB_T28181-2016.pdf
国标28181-2016版本检测,由于文件过大,而且博客不支持上传文件,需要GB28181-2016协议文档和公安一所检测文档的可以私信我,QQ:123011785 I C S1 3. 3 1 0 A ...
- poj3264 - Balanced Lineup(RMQ_ST)
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 45243 Accepted: 21240 ...
- POJ 3264 Balanced Lineup
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 53629 Accepted: 25223 ...
- HDOJ 3709 Balanced Number
数位DP... Balanced Number Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java ...
- Gold Balanced Lineup - poj 3274 (hash)
这题,看到别人的解题报告做出来的,分析: 大概意思就是: 数组sum[i][j]表示从第1到第i头cow属性j的出现次数. 所以题目要求等价为: 求满足 sum[i][0]-sum[j][0]=sum ...
- poj 3264 Balanced Lineup RMQ问题 线段树
For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One d ...
- SBT模版(Size Balanced Tree)
关于SBT的介绍及学习,请戳这里. SBT模版: /************************************************* 数据结构: SBT(Size Balanced ...
- 1702: [Usaco2007 Mar]Gold Balanced Lineup 平衡的队列
1702: [Usaco2007 Mar]Gold Balanced Lineup 平衡的队列 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 510 ...
最新文章
- 10冰点还原安装不了_荣耀智慧屏X1性能有多强?荣耀智慧屏X1怎么安装第三方软件?...
- python3.x中如何实现print不换行
- 【人物】Paul Graham: 卑鄙的人一定失败
- boost::python模块显示重载和自动转换问题的示例
- 如何使用SAP云平台的Notification服务给Android应用推送通知消息
- 2021高考襄阳四中成绩查询,襄阳四中2020年高考成绩怎么样(高考喜报)
- 异步任务,邮箱任务,定时任务
- VM虚拟机上的CentOS 7系统重置root用户密码
- SSIS 错误代码 DTS_E_OLEDB_EXCEL_NOT_SUPPORTED 没有可用的 OLE DB 访问接口 SSIS 的 64 位版本中不支持 Excel 连接管理器...
- .net VS 全角问题
- Photoshop操作秘籍
- js触发click事件
- vue ref 绑定的事件需要移除吗_vue生命周期
- 2019全球logo设计趋势
- 洛阳师范学院计算机组成原理,洛阳师范学院2010-2011-2《计算机组成原理》试卷b(智爱娟).doc...
- 175个常用诗词语句出处
- psd 将分组合并导出png图片
- 数据结构基本代码汇总
- 2019 CSP-J 真题 题目、答案以及解析
- c语言入门1.2.3 百度云,C语言入门1.2.3--一个老鸟的C语言学习心得(附光盘)
热门文章
- php回调函数求1+2+3+...+100的值_PHP全栈学习笔记6
- mysql超级_Mysql 超级快速入门
- java 动态拼接sql_动态SQL拼接工具类
- n阶完全图边和顶点关系。_正N边型的完全图被分割成几个多边形
- 九十、深入弹性(Flex)布局
- 六、Go编程语言中的函数式编程
- ICLR 2022入选论文线上分享预告:一作解读,不容错过
- ICLR 2021 | 显存不够?不妨抛弃端到端训练
- 别再用假任务做小样本学习实验了!来试试这个全新基准数据集
- 近期大热的AutoML领域,都有哪些值得读的论文?