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 }
  • 相关阅读:
    Use Module and Function instead of Class in Python
    以命令行方式使用Desktop版Ubuntu
    python中两种拷贝目录方法的比较
    查找重复文件并删除的工具
    Manage sshd Service on CentOS
    Java多线程间的数据共享
    并发 总结
    MapReduce 过程分析
    java能不能自己写一个类叫java.lang.System/String正确答案
    生产者消费者模式--阻塞队列--LOCK,Condition--线程池
  • 原文地址:https://www.cnblogs.com/hsd-/p/5747459.html
Copyright © 2011-2022 走看看