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 }
  • 相关阅读:
    强行拉取git分支到覆盖到本地
    提交git报错:rejected non fast forward
    表单验证
    获取ipv6转换ipv4
    使用js获取外网ip
    --打坐篇-学习的一些笔记-03--
    --心法篇-《我和我的Angular》-01-学习笔记--
    --打坐篇-学习的一些笔记-02--
    --打坐篇-学习的一些笔记-01--
    --前端派-练功房-01-关于this指向的一些案例补充--
  • 原文地址:https://www.cnblogs.com/hsd-/p/5747459.html
Copyright © 2011-2022 走看看