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 }
  • 相关阅读:
    Splay 详解
    莫队套值域分块
    浅谈区间众数
    回滚莫队分块
    带修莫队分块
    微服务规划准则
    mysql查询包含逗号的数据,并逗号拆分为多行展现
    python mysql 单连接和连接池简单示例
    代理模式八:装饰者模式
    代理模式七:迭代器模式
  • 原文地址:https://www.cnblogs.com/hsd-/p/5747459.html
Copyright © 2011-2022 走看看