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个列,在这些列 ...
随机推荐
- nodejs安装错误
network错误: npm ERR! network tunneling socket could not be established, cause=connect ECONNREFUSED 12 ...
- NOIP临考经验【转】
NOIP临考经验 1.提前15分钟入场,此时静坐调整心态,适当的深呼吸 2.打开编辑器并调整为自己喜欢的界面 3.熟悉文件目录,写好准确无误的代码模板 4.压缩包或许还不能解压,但是文件名已经可以知道 ...
- [洛谷P4949]最短距离
题目大意:给一棵基环树,两种操作: $1\;x\;y:$把第$x$条边长度改成$y$ $2\;x\;y:$查询$x$到$y$的最短距离 题解:发现最短距离只有两种可能,第一个是树上的距离,第二种是经过 ...
- [TJOI2018]数学计算 线段树
---题面--- 题解: ,,,考场上看到这题,没想到竟然是省选原题QAQ,考场上把它当数学题想了好久,因为不知道怎么处理有些数没有逆元的问题....知道这是线段树后恍然大悟. 首先可以一开始就建出一 ...
- C&C++——C函数与C++函数相互调用问题
C C++相互调用 在项目中融合C和C++有时是不可避免的,在调用对方的功能函数的时候,或许会出现这样那样的问题,但只要我的C代码和我的C++代码分别都能成功编译,那其他就不是问题.近来在主程序是C语 ...
- Educational Codeforces Round 58 (Rated for Div. 2) 题解
Educational Codeforces Round 58 (Rated for Div. 2) 题目总链接:https://codeforces.com/contest/1101 A. Min ...
- Cannot load project: com.intellij.ide.plugins.PluginManager$StartupAbortedException
今天电脑突然蓝屏,idea异常关闭,开机重启后,打开idea,点击项目出现 Cannot load project: com.intellij.ide.plugins.PluginManager$St ...
- Spring学习--通过注解配置 Bean (二)
在 classpath 中扫描组件: 当在组件类上使用了特定的注解之后 , 还需要在 Spring 的配置文件中声明 <context:component-scan>: base-pack ...
- 常用原生客户端js
var el = document.createElement('pre'); // 创建 <pre></pre>元素 el.id = 'sss'; // 添加id <p ...
- HDU1596 find the safest road---(最短路径dijkstra,#变形#)
http://acm.hdu.edu.cn/showproblem.php?pid=1596 分析: 题目要找一条安全度最高的路,安全度计算方法 Safe(P) = s(e1)*s(e2)…*s ...