【CF Edu 28 A. Curriculum Vitae】
time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.
During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV.
More formally, you are given an array s1, s2, ..., sn of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one.
Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV.
Input
The first line contains one integer number n (1 ≤ n ≤ 100).
The second line contains n space-separated integer numbers s1, s2, ..., sn (0 ≤ si ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one.
Output
Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one.
Examples
input
4
1 1 0 1
output
3
input
6
0 1 0 0 1 0
output
4
input
1
0
output
1
【翻译】给出一个长度为n的01序列,现在可以删除一些数,使得最终序列满足对于任何一个1后面所有位置都不会有0,求剩余元素个数的最大值。
题解:
①根据题目,可以的枚举哪个地方开始选择1,那么之后的0都要删除。
②实现方法是分别维护0和1的前缀,然后O(n)扫一遍就可以了。
#include<stdio.h>
#include<algorithm>
#define go(i,a,b) for(int i=a;i<=b;i++)
using namespace std;int n,ans,t,a[2][102];
int main()
{
scanf("%d",&n);
go(i,1,n)scanf("%d",&t),a[0][i]=a[0][i-1],a[1][i]=a[1][i-1],a[t][i]++;
go(i,1,n)if(a[1][i]!=a[1][i-1])ans=max(ans,a[0][i]+a[1][n]-a[1][i-1]);
ans=max(ans,a[0][n]);printf("%d\n",ans);
return 0;
}//Paul_Guderian
这是1999年的冬天,从来没经历过的寒冷,
街边的楼群指着蓝天,人们都蜷缩在大衣里行色匆匆。——————汪峰《再见二十世纪》
【CF Edu 28 A. Curriculum Vitae】的更多相关文章
- 【CF Edu 28 C. Four Segments】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 【CF Edu 28 B. Math Show】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 【2020.11.28提高组模拟】T1染色(color)
[2020.11.28提高组模拟]T1染色(color) 题目 题目描述 给定 \(n\),你现在需要给整数 \(1\) 到 \(n\) 进行染色,使得对于所有的 \(1\leq i<j\leq ...
- 【CF edu 30 D. Merge Sort】
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【Cf edu 30 B. Balanced Substring】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 【CF Round 434 B. Which floor?】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 【2020.11.28提高组模拟】T2 序列(array)
序列(array) 题目描述 给定一个长为 \(m\) 的序列 \(a\). 有一个长为 \(m\) 的序列 \(b\),需满足 \(0\leq b_i \leq n\),\(\sum_{i=1}^ ...
- B. Lost Number【CF交互题 暴力】
B. Lost Number[CF交互题 暴力] This is an interactive problem. Remember to flush your output while communi ...
- 【CF 453A】 A. Little Pony and Expected Maximum(期望、快速幂)
A. Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megabytes ...
随机推荐
- ABAP Table Control
SAP中,Table Control是在Screen中用的最广泛的控件之一了,可以实现对多行数据的编辑. 简单来说,Table Control是一组屏幕元素在Screen上的重复出现,这就是它与普通 ...
- python--随笔一
1.format函数--根据关键字和位置选择性插入数据 In [11]: '{mingzi}jintian{dongzuo}'.format(mingzi='duzi',dongzuo='i love ...
- selenium破解极限
一共分为两端段代码: 第一段:获取cookie 第二段:通过cookie登陆 这里以百度云为例: 第一部分:保存cookies,直接在cmd中执行就好 >>> from seleni ...
- tcl之string操作-length/index/range/replace
- 华为模拟器ensp代码错误2,41,40问题的解决
win8+ensp320 ensp这是个神奇的软件,问题竟然出现的这么莫名其妙..前一秒还是好的时候,后一秒就立马出现了问题.不过不要慌...沉住气,把这篇文章看下去. 博主从昨天开始,ensp神奇的 ...
- 快速排序算法Java实现
1) 通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都要小,然后再按此方法对这两部分数据分别进行快速排序,整个排序过程可以递归进行 示例: package ...
- C语言字符篇(三)字符串比较函数
#include <string.h> int strcmp(const char *s1, const char *s2); 比较字符串s1和s2 int strncmp(const ...
- Card Hand Sorting 18中南多校第一场C题
一.题意 随机给你一堆牌(标准扑克牌),之后让你按照: 第一优先规则:所有相同花色的在一起 第二优先规则:所有相同花色的必须按照升序或者降序排列 问,你最少要拿出多少张牌插入到其他的地方以维持这个状况 ...
- 1096: [ZJOI2007]仓库建设
1096: [ZJOI2007]仓库建设 思路 斜率优化. 代码 #include<cstdio> #include<iostream> using namespace std ...
- 获取HTTP请求头中的地址
技术交流群:233513714 public static String getIpAddr(HttpServletRequest request) { String ip = request.get ...