zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 15 A dp

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

    You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.

    A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.

    Input

    The first line contains single positive integer n (1 ≤ n ≤ 105) — the number of integers.

    The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).

    Output

    Print the maximum length of an increasing subarray of the given array.

    Examples
    input
    5
    1 7 2 11 15
    output
    3
    input
    6
    100 100 100 100 100 100
    output
    1
    input
    3
    1 2 3
    output
    3

    题意:连续的最长上升子序列的长度
    题解:dp[i]表示以a[i]结尾的 连续的最长上升子序列的长度
     1 /******************************
     2 code by drizzle
     3 blog: www.cnblogs.com/hsd-/
     4 ^ ^    ^ ^
     5  O      O
     6 ******************************/
     7 //#include<bits/stdc++.h>
     8 #include<iostream>
     9 #include<cstring>
    10 #include<cstdio>
    11 #include<map>
    12 #include<algorithm>
    13 #include<queue>
    14 #include<cmath>
    15 #define ll __int64
    16 #define PI acos(-1.0)
    17 #define mod 1000000007
    18 using namespace std;
    19 int n;
    20 int a[100005];
    21 int dp[100005];
    22 int ans=0;
    23 int main()
    24 {
    25     scanf("%d",&n);
    26     int ans=0;
    27     for(int i=1;i<=n;i++)
    28         scanf("%d",&a[i]);
    29     dp[1]=1;
    30     ans=1;
    31     for(int i=2;i<=n;i++)
    32     {
    33         if(a[i]>a[i-1])
    34         {
    35             dp[i]=dp[i-1]+1;
    36             ans=max(ans,dp[i]);
    37         }
    38         else
    39             dp[i]=1;
    40     }
    41     cout<<ans<<endl;
    42     return 0;
    43 }
  • 相关阅读:
    calendar.getTimeInMillis() 和 System.currentTimeMillis() 的区别
    微信小程序中使用 <web-view> 内嵌 H5 时,登录问题的处理方法
    小程序 TabBar 定制
    webpack 代码优化压缩方法
    react-router v4 按需加载的配置方法
    axios发送post请求,如何提交表单数据?
    react中键盘enter事件处理
    常用证件正则表达式
    react中input自动聚焦问题
    React Router v4 页面传值的三种方法
  • 原文地址:https://www.cnblogs.com/hsd-/p/5747459.html
Copyright © 2011-2022 走看看