zoukankan      html  css  js  c++  java
  • POJ 1836 Alignment

    Alignment
     
    Time Limit: 1000MS   Memory Limit: 30000K
    Total Submissions: 10672   Accepted: 3414

    Description

    In the army, a platoon is composed by n soldiers. During the morning inspection, the soldiers are aligned in a straight line in front of the captain. The captain is not satisfied with the way his soldiers are aligned; it is true that the soldiers are aligned in order by their code number: 1 , 2 , 3 , . . . , n , but they are not aligned by their height. The captain asks some soldiers to get out of the line, as the soldiers that remain in the line, without changing their places, but getting closer, to form a new line, where each soldier can see by looking lengthwise the line at least one of the line's extremity (left or right). A soldier see an extremity if there isn't any soldiers with a higher or equal height than his height between him and that extremity. 

    Write a program that, knowing the height of each soldier, determines the minimum number of soldiers which have to get out of line. 

    Input

    On the first line of the input is written the number of the soldiers n. On the second line is written a series of n floating numbers with at most 5 digits precision and separated by a space character. The k-th number from this line represents the height of the soldier who has the code k (1 <= k <= n). 

    There are some restrictions: 
    • 2 <= n <= 1000 
    • the height are floating numbers from the interval [0.5, 2.5] 

    Output

    The only line of output will contain the number of the soldiers who have to get out of the line.

    Sample Input

    8
    1.86 1.86 1.30621 2 1.4 1 1.97 2.2
    

    Sample Output

    4
    分析:令到原队列的最少士兵出列后,使得新队列任意一个士兵都能看到左边或者右边的无穷远处,最大上升子序列的变种,通过从左到右和从右到左分别求最长上升子序列,然后任意两个士兵的最大上升子序列的长度则为最后留下的士兵的人数。
    #include <stdio.h>
    #include <iostream>
    using namespace std;
    
    void Find(double arr[], int n, int dp[])
    {
        int Max = -1;
        dp[0] = 1;
        for (int i = 1; i < n; i++)
        {
            Max = 0;
            dp[i] = 1;
            for (int j = 0; j < i; j++)
            {
                if (arr[i] > arr[j] && dp[j] + 1 > dp[i])
                {
                    dp[i] = dp[j] + 1;
                }
            }
        }
    }
    
    int main()
    {
        int n;
        int Max = -1;
        double a[1005];
        double b[1005];
        int dp[1005];
        int dp1[1005];
        scanf("%d", &n);
        dp[n] = dp1[n] = 0;
        for (int i = 0; i < n; i++)
        {
            scanf("%lf", &a[i]);
            b[n - 1 - i] = a[i];
        }
        Find(a, n, dp);
        Find(b, n, dp1);
        for (int i = 0; i < n; i++)
        {
            for (int j = i + 1; j < n; j++)
            {
                if (dp[i] + dp1[n - j - 1] > Max)
                {
                    Max = dp[i] + dp1[n - j - 1];
                }
            }
        }
        printf("%d\n", n - Max);
        return 0;
    }
     
  • 相关阅读:
    Show, Attend and Tell: Neural Image Caption Generation with Visual Attention
    (转)Awesome GAN for Medical Imaging
    (转)Awesome Object Detection
    (转)Awesome PyTorch List
    深度学习课程笔记(十七)Meta-learning (Model Agnostic Meta Learning)
    深度学习课程笔记(十六)Recursive Neural Network
    (转)Multi-Object-Tracking-Paper-List
    深度学习课程笔记(十五)Recurrent Neural Network
    (转)Awsome Domain-Adaptation
    论文阅读:Learning Visual Question Answering by Bootstrapping Hard Attention
  • 原文地址:https://www.cnblogs.com/lzmfywz/p/3108402.html
Copyright © 2011-2022 走看看