当前位置:网站首页>P1564 膜拜
P1564 膜拜
2022-08-10 01:57:00 【Recursi】
题目描述
神牛有很多…当然…每个同学都有自己衷心膜拜的神牛.
某学校有两位神牛,神牛甲和神牛乙。新入学的 n n n 位同学们早已耳闻他们的神话。
所以,已经衷心地膜拜其中一位了。现在,老师要给他们分机房。但是,要么保证整个机房都是同一位神牛的膜拜者,或者两个神牛的膜拜者人数差不超过 m m m。另外,现在 n n n 位同学排成一排,老师只会把连续一段的同学分进一个机房。老师想知道,至少需要多少个机房。
输入格式
输入文件第一行包含两个整数 n n n 和 m m m。
第 2 2 2 到第 ( n + 1 ) (n + 1) (n+1) 行,每行一个非 1 1 1 即 2 2 2 的整数,第 ( i + 1 ) (i + 1) (i+1) 行的整数表示第 i i i 个同学崇拜的对象, 1 1 1 表示甲, 2 2 2 表示乙。
输出格式
输出一个整数,表示最小需要机房的数量。
样例 #1
样例输入 #1
5 1
2
2
1
2
2
样例输出 #1
2
提示
数据规模与约定
- 对于 30 % 30\% 30% 的数据,保证 1 ≤ n , m ≤ 50 1 \le n,m \le 50 1≤n,m≤50。
- 对于 100 % 100\% 100% 的数据,保证 1 ≤ n , m ≤ 2500 1 \le n,m \le 2500 1≤n,m≤2500。
/* * @Description: To iterate is human, to recurse divine. * @Autor: Recursion * @Date: 2022-08-09 23:25:49 * @LastEditTime: 2022-08-09 23:39:36 */
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 1e9 + 10;
const int N = 1e6;
int n,m;
int sum[N];
int dp[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
fill(dp + 1,dp + 1 + n,INF);
for(int i = 1;i <= n;i ++){
int x;
cin >> x;
if(x == 1)
sum[i] = sum[i - 1] + 1;
else
sum[i] = sum[i - 1] - 1;
}
for(int i = 1;i <= n;i ++)
for(int j = 1;j <= i;j ++)
if(abs(sum[i] - sum[j - 1] )==i - j + 1||abs(sum[i]- sum[j - 1]) <= m)
dp[i] = min(dp[i],dp[j - 1] + 1);
cout << dp[n] << endl;
return 0;
}```
边栏推荐
- 月薪35K,靠八股文就能做到的事,你居然不知道
- 常用正则备查
- Algorithm and voice dialogue direction interview question bank
- Database management tool: dynamic read-write separation
- SQL注入的order by ,limit与宽字节注入
- Initial attempt at UI traversal
- 【论文粗读】(NeurIPS 2020) SwAV:对比聚类结果的无监督视觉特征学习
- 实操|风控模型中常用的这三种预测方法与多分类场景的实现
- 2022年8月1日-8月7日(本周10小时,合计1422小时,剩余8578小时)
- 781. 森林中的兔子
猜你喜欢
随机推荐
中文NER的SOTA:RICON
Data Governance (5): Metadata Management
华为HCIE云计算之FC添加ipsan数据存储
中英文互译在线翻译-在线翻译软件
常用正则备查
【二叉树-中等】508. 出现次数最多的子树元素和
In automated testing, test data is separated from scripts and parameterized methods
Open3D 中点细分(网格细分)
JCMsuite—单模光纤传播模式
C# 正则表达式分组查询
高并发+海量数据下如何实现系统解耦?【下】
Pagoda server PHP+mysql web page URL jump problem
【二叉树-中等】687. 最长同值路径
SQLserver adds a judgment
[Syntax sugar] About the mapping of category strings to category numeric ids
高压之下,必有懦夫
翻译软件免费版下载-免费版翻译软件下载
浏览器中location详解
Unity reports Unsafe code may only appear if compiling with /unsafe. Enable “Allow ‘unsafe’ code” in Pla
web crawler error









