题目链接:http://codeforces.com/problemset/problem/702/A

题意:

  给你N个数,a[0], a[1], a[2], ....., a[n-1],让你找出最长的连续上升子序列中元素的个数。

思路:

  设dp[i]代表以a[i]结尾的连续上升子序列中元素的个数,那么dp[i] = (a[i] > a[i - 1] ? dp[i - 1] + 1 : 1),含义是如果a[i]比a[i-1]大,那么a[i]可以加入到以a[i-1]为尾的最长连续上升子序列末尾,取代a[i-1]成为新的末尾,原本的长度加1。否则a[i]单独作为一个子序列,长度为1。然后找到这个数组的最大值就OK了。实现时,可以用一个滚动变量来代替这个数组,优化空间复杂度。

代码:

  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <cstdlib>
  6. #include <stack>
  7. #include <queue>
  8. #include <vector>
  9. #include <algorithm>
  10. #include <string>
  11.  
  12. typedef long long LL;
  13. using namespace std;
  14.  
  15. int main() {
  16. int n, ans = -, cnt = , a, b;
  17. scanf("%d%d", &n, &a);
  18. for(int i = ; i < n; i++) {
  19. scanf("%d", &b);
  20. b > a ? cnt++ : (ans = ( cnt > ans ? cnt : ans) , cnt = );
  21. a = b;
  22. }
  23. printf("%d\n", cnt > ans ? cnt : ans);
  24. return ;
  25. }

Codeforces 702A Maximum Increase(dp)的更多相关文章

  1. Codeforces - 702A - Maximum Increase - 简单dp

    DP的学习计划,刷 https://codeforces.com/problemset?order=BY_RATING_ASC&tags=dp 遇到了这道题 https://codeforce ...

  2. CodeForces 702A Maximum Increase

    简单$dp$. 如果$a[i]>a[i-1]$,那么$dp[i]=dp[i-1]+1$.否则,$dp[i]=1$.答案为$dp[i]$中的最大值. #pragma comment(linker, ...

  3. codeforces 702A A. Maximum Increase(水题)

    题目链接: A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input sta ...

  4. Codeforces Educational Codeforces Round 15 A. Maximum Increase

    A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Educational Codeforces Round 15 A dp

    A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. cf702A Maximum Increase

    A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. Codeforces 484B Maximum Value(高效+二分)

    题目链接:Codeforces 484B Maximum Value 题目大意:给定一个序列,找到连个数ai和aj,ai%aj尽量大,而且ai≥aj 解题思路:类似于素数筛选法的方式,每次枚举aj,然 ...

  8. Codeforces C. Maximum Value(枚举二分)

    题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. [Codeforces 1201D]Treasure Hunting(DP)

    [Codeforces 1201D]Treasure Hunting(DP) 题面 有一个n*m的方格,方格上有k个宝藏,一个人从(1,1)出发,可以向左或者向右走,但不能向下走.给出q个列,在这些列 ...

随机推荐

  1. 判断腾讯QQ是否在线

    http://webpresence.qq.com/getonline?Type=1&1617052138: 判断腾讯QQ是否在线接口. 下面是个简单的例子: <!doctype htm ...

  2. BZOJ2437 NOI2011兔兔与蛋蛋(二分图匹配+博弈)

    首先将棋盘黑白染色,不妨令空格处为黑色.那么移动奇数次后空格一定处于白色格子,偶数次后空格一定处于黑色格子.所以若有某个格子的棋子颜色与棋盘颜色不同,这个棋子就是没有用的.并且空格与某棋子交换后,棋子 ...

  3. [poj] 2396 [zoj] 1994 budget || 有源汇的上下界可行流

    poj原题 zoj原题 //注意zoj最后一行不要多输出空行 现在要针对多赛区竞赛制定一个预算,该预算是一个行代表不同种类支出.列代表不同赛区支出的矩阵.组委会曾经开会讨论过各类支出的总和,以及各赛区 ...

  4. Failed with exception MetaException(message:javax.jdo.JDODataStoreException: Error(s) were found while auto-creating/validating the datastore for classes.

    hive (db_emp)> load data local inpath '/opt/datas/emp.txt' into table emp_part partition(`date`=' ...

  5. 【BZOJ3887】【Usaco2015 Jan】Grass Cownoisseur Tarjan+Spfa

    我们可以看出这个东西可以缩点成DAG,因为我们在所称的点里用特技的话,要么没用,要么削弱自己对点的收割能力与边的联通权,所以我们缩完点之后在图上枚举反向的变,因为我们只可能反向一条边,而且我们知道在这 ...

  6. Spring源码解析-基于注解依赖注入

    在spring2.5版本提供了注解的依赖注入功能,可以减少对xml配置. 主要使用的是 AnnotationConfigApplicationContext: 一个注解配置上下文 AutowiredA ...

  7. 小K的农场

    小K的农场 题目描述 小K在MC里面建立很多很多的农场,总共n个,以至于他自己都忘记了每个农场中种植作物的具体数量了,他只记得一些含糊的信息(共m个),以下列三种形式描述: 农场a比农场b至少多种植了 ...

  8. Spring表达式语言之SpEL

    •Spring 表达式语言(简称SpEL):是一个支持运行时查询和操作对象图的强大的表达式语言. •语法类似于 EL:SpEL 使用 #{…} 作为定界符,所有在大框号中的字符都将被认为是 SpEL ...

  9. 【poj3693-重复次数最多的连续重复子串】后缀数组

    题意:给定一个串,长度<=10^5,求它重复次数最多的连续重复子串(输出字典序最小的那个). 例如ccabcabc,答案就是abcabc 一开始没想清楚,结果调了好久. 原理: 按照L划分,因为 ...

  10. [object-c 2.0 程序设计]object-c file handle (二)

    // // main.m // cmdTry // // Created by Calos Chen on 2017/8/21. // Copyright © 2017年 Calos Chen. Al ...