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 }
  • 相关阅读:
    05 | 深入浅出索引(下)
    04 | 深入浅出索引(上)
    03 | 事务隔离:为什么你改了我还看不见?
    02 | 日志系统:一条SQL更新语句是如何执行的?
    01 | 基础架构:一条SQL查询语句是如何执行的?
    orm的惰性机制
    简易的迁移
    rails 中 preload、includes、Eager load、Joins 的区别
    换种方式去分页
    Scala function programming
  • 原文地址:https://www.cnblogs.com/hsd-/p/5747459.html
Copyright © 2011-2022 走看看