【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 ...
随机推荐
- 【学时总结】 ◆学时·II◆ IDA*算法
[学时·II] IDA*算法 ■基本策略■ 如果状态数量太多了,优先队列也难以承受:不妨再回头看DFS-- A*算法是BFS的升级,那么IDA*算法是对A*算法的再优化,同时也是对迭代加深搜索(IDF ...
- 如何在maven中的项目使用tomcat插件
在pom.xml中引入tomcat7插件,具体示例代码如下: <project> <build> <plugins> <plugin> <grou ...
- Java OOP——第五章 异常
1. 尝试通过if-else来解决异常问题: Eg: public class Test2 { public static void main(String[] args) { ...
- scrapy--BeautifulSoup
BeautifulSoup官方文档:https://beautifulsoup.readthedocs.io/zh_CN/latest/#id8 太繁琐的,精简了一些自己用的到的. 1.index.h ...
- php-5.6.26源代码 - opcode处理器的注入
.初始化 opcode处理器列表 // main实现在文件“php-5.6.26\sapi\cgi\cgi_main.c” int main(int argc, char *argv[]) { if ...
- 学习Pytbon第十天 函数2 内置方法和匿名函数
print( all([1,-5,3]) )#如果可迭代对象里所有元素都为真则返回真.0不为真print( any([1,2]) )#如果数据里面任意一个数据为真返回则为真a= ascii([1,2, ...
- C++基础 静态成员
静态成员是类的所有 对象共有的变量,在编译 阶段就必须分配空间. 需要注意: (1)静态成员变量的定义和使用 class Test{ static int a; }; ; void main() {} ...
- 財務会計管理(FI&CO)
FI(財務会計)系のSAP DBテーブル.随時更新していきます. [勘定コードマスタ]SKA1: 勘定コードマスタ(勘定コード表データ)SKB1: 勘定コードマスタ(会社コードデータ)SKAT: テキ ...
- CSS计数器(自定义列表)
概念 CSS3计数器(CSS Counters)可以允许我们使用css对页面中的任意元素进行计数,实现类似于有序列表的功能(自定义有序列表) 与有序列表相比,它的突出特性在于可以对任意元素计数,同时实 ...
- loadrunner检查点设置失败,日志中SaveCount无法被正常统计出来
在脚本正确的情况下的web_reg_find检查点检查失败,SaveCount无法被正常统计出来. 在检查项Text为中文的情况下, ******(我是被录制下来的代码) web_reg_find(& ...