Codeforces 702A Maximum Increase(dp)
题目链接: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了。实现时,可以用一个滚动变量来代替这个数组,优化空间复杂度。
代码:
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <string> typedef long long LL;
using namespace std; int main() {
int n, ans = -, cnt = , a, b;
scanf("%d%d", &n, &a);
for(int i = ; i < n; i++) {
scanf("%d", &b);
b > a ? cnt++ : (ans = ( cnt > ans ? cnt : ans) , cnt = );
a = b;
}
printf("%d\n", cnt > ans ? cnt : ans);
return ;
}
Codeforces 702A Maximum Increase(dp)的更多相关文章
- Codeforces - 702A - Maximum Increase - 简单dp
DP的学习计划,刷 https://codeforces.com/problemset?order=BY_RATING_ASC&tags=dp 遇到了这道题 https://codeforce ...
- CodeForces 702A Maximum Increase
简单$dp$. 如果$a[i]>a[i-1]$,那么$dp[i]=dp[i-1]+1$.否则,$dp[i]=1$.答案为$dp[i]$中的最大值. #pragma comment(linker, ...
- codeforces 702A A. Maximum Increase(水题)
题目链接: A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input sta ...
- 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 ...
- Educational Codeforces Round 15 A dp
A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...
- cf702A Maximum Increase
A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces 484B Maximum Value(高效+二分)
题目链接:Codeforces 484B Maximum Value 题目大意:给定一个序列,找到连个数ai和aj,ai%aj尽量大,而且ai≥aj 解题思路:类似于素数筛选法的方式,每次枚举aj,然 ...
- Codeforces C. Maximum Value(枚举二分)
题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...
- [Codeforces 1201D]Treasure Hunting(DP)
[Codeforces 1201D]Treasure Hunting(DP) 题面 有一个n*m的方格,方格上有k个宝藏,一个人从(1,1)出发,可以向左或者向右走,但不能向下走.给出q个列,在这些列 ...
随机推荐
- jquery/js iframe 元素操作
1.判断id/ class 是否存在? <script> $(function(){ if(("#id_name").length()>0){ //如果id 存在 ...
- 2018牛客多校第一场 A.Monotonic Matrix
题意: 给一个n*m的矩阵赋值(0,1,2).使得每个数都不小于它左面和上面的数. 题解: 构建0和1的轮廓线.对于单独的轮廓线,共需要往上走n步,往右走m步.有C(n+m,n)种方式. 两个轮廓线的 ...
- 【BZOJ 1070】[SCOI2007]修车 费用流
就是拆个点限制一下(两点一排一大片),这道题让我注意到了限制这个重要的词.我们跑网络流跑出来的图都是有一定意义的,一般这个意义就对应了问题的一种方案,一般情况下跑一个不知道对不对的方案是相对容易的我们 ...
- BZOJ 3319 黑白树 并查集+线段树
这这这这这这什么毒瘤题!!!!!!!!!!!!!!!!!!!!!!!!!!!! 卡LCT(优秀的LCT由于是均摊本身就带着2,3的常数在,而且这道题对于LCT标记十分难维护,又得乘上4,5然后就炸了) ...
- 怎么把linux的磁盘映射到windows上
步骤如下: 右击如下的computer: 然后选择:Map network drive... 然后在下图按图中所示操作: 最后成功如下图所示:
- java 多线程 原子性
原子性 原子性:原子操作是不能被线程调度机制中断的操作,一旦操作开始,那么它就一定可以在可能发生的“上下文切换”之前(切换到其他线程执行)执行完毕. 依赖原子性是很棘手且很危险的,除非你是并发专家,否 ...
- CSS中的@ AT规则
大家可能在CSS中见到过字符@然后加一些关键字的用法,这种用法就称之为AT规则,在CSS中,种类还是很多的,这里总结列举下. 常规规则 所谓“常规规则”指的是语法类似下面的规则: @[KEYWORD] ...
- CSS3学习笔记之径向展开菜单
效果截图: HTML代码: <div class="menu-wrap"> <nav> <a href="" class=&quo ...
- Spring任务调度<task:scheduled-tasks>【含cron参数详解】 (转载)
Spring内部有一个task是Spring自带的一个设定时间自动任务调度 task使用的时候很方便,但是他能做的东西不如quartz那么的多! 可以使用注解和配置两种方式,配置的方式如下 引入Spr ...
- 【BZOJ】2442: [Usaco2011 Open]修剪草坪
[算法]动态规划 [题解] 万物皆动规,每时每刻都要想着DP!特别是这种明显可以序列递推的题目. 一个简单的思路是f[i]表示前i个选择合法方案(第i个可选可不选)的最大效率 f[i]=max(f[i ...