必威体育Betway必威体育官网
当前位置:首页 > IT技术

LIS

时间:2019-10-03 02:15:38来源:IT技术作者:seo实验室小编阅读:76次「手机版」
 

lis

Super Jumping! Jumping! Jumping!

题目链接:HDU - 1087 

Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now. 

The game can be played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are marked by a positive integer or “start” or “end”. The player starts from start-point and must jumps into end-point finally. In the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a Minimum and end-point is a maximum.). And all players cannot go backwards. One jumping can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path. 

Your task is to output the maximum value according to the given chessmen list. 

Input

Input contains multiple test cases. Each test case is described in a line as follow:

N value_1 value_2 …value_N 

It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int. 

A test case starting with 0 terminates the input and this test case is not to be processed. 

Output

For each case, print the maximum according to rules, and one line one case. 

Sample Input

3 1 3 2
4 1 2 3 4
4 3 3 2 1
0

Sample Output

4
10
3

求lis

所有棋子都用正整数或“开始”或“结束”标记。玩家从起点开始,最后必须跳进终点。在跳跃的过程中,玩家将访问路径中的棋子,但是每个人都必须从一个棋子跳到另一个棋子绝对大(你可以假定起点是最小的,终点是最大的)。所有的球员都不能倒退。一个跳跃可以从棋子到下一个,也可以穿过许多棋子,甚至可以直接从终点到达终点。当然,在这种情况下你得零分。一个球员是一个胜利者,而且只有当他能获得更大的分数,根据他的跳跃解决方案。注意,你的分数来自于你在跳跃路径中的棋子的价值总和。你的任务是根据给定的棋子列表输出最大值。

#include<cstdio>
#include<algorithm>
#include<cstring>
#define maxn 2009
using namespace std;

int a[maxn];
int dp[maxn];
int n,ans;
int main()
{
    while(~scanf("%d",&n),n)
    {
        memset(dp,0,sizeof(dp));
        for(int i = 1; i <= n;i++)
        {
            scanf("%d",&a[i]);
        }
        dp[1] = a[1];
        ans = dp[1];
        for(int i = 2;i <= n;i++)
        {
            dp[i] = a[i];
            for(int j = 1; j < i; j++)
            {
                if(a[i] > a[j])
                dp[i] = max(dp[i],dp[j]+a[i]);
            }
            ans = max(ans,dp[i]);
        }
        printf("%d\n",ans);
    }
    return 0;
}

最少拦截系统

HDU - 1257 

某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹. 

怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统. 

Input

输入若干组数据.每组数据包括:导弹总个数(正整数),导弹依此飞来的高度(雷达给出的高度数据是不大于30000的正整数,用空格分隔) 

Output

对应每组数据输出拦截所有导弹最少要配备多少套这种导弹拦截系统. 

Sample Input

8 389 207 155 300 299 170 158 65

Sample Output

2
#include<cstdio>
using namespace std;

int dp[30001];
int a[30001];
int n;
int lis()
{
    dp[1] = 1;
    int ans = 1;
    for(int i = 2; i <= n; i++)
    {
        int m = 0;
        for(int j = 1; j < i ; j++)
        {
            if(dp[j] > m && a[j] < a[i])
                m = dp[j];
        }
        dp[i] = m + 1;
        if(dp[i] > ans)
            ans = dp[i];
    }
    return ans;
}

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        for(int i = 1; i <= n; i++)
        scanf("%d",&a[i]);
        printf("%d\n",lis());
    }
    return 0;
}

Longest ordered Subsequence

POJ - 2533 

A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence ( a1, a2, ..., aN) be any sequence ( ai1, ai2, ..., aiK), where 1 <= i1 < i2 < ... < iK <= N. For example, sequence (1, 7, 3, 5, 9, 4, 8) has ordered subsequences, e. g., (1, 7), (3, 4, 8) and many others. All longest ordered subsequences are of length 4, e. g., (1, 3, 5, 8). 

Your program, when given the numeric sequence, must find the length of its longest ordered subsequence.

Input

The first line of input file contains the length of sequence N. The second line contains the elements of sequence - N integers in the range from 0 to 10000 each, separated by spaces. 1 <= N <= 1000

Output

Output file must contain a single integer - the length of the longest ordered subsequence of the given sequence.

Sample Input

7
1 7 3 5 9 4 8

Sample Output

4
#include<cstdio>
#include<algorithm>
using namespace std;

int dp[1111],a[1111];
int n;

int lis()
{
    int ans,m;
    dp[1] = 1;
    ans = 1;
    for(int i = 2; i <= n ; i++)
    {
        m = 0;
        for(int j = 1; j < i; j++)
        {
            if(a[i] > a[j] && m < dp[j])
                m = dp[j];
        }
        dp[i] = m + 1;
        if(dp[i] > ans)
            ans = dp[i];
    }
    return ans;
}

int main()
{
    scanf("%d",&n);
    for(int i = 1; i <= n; i++)
        scanf("%d",&a[i]);
    printf("%d\n",lis());
    return 0;
}

相关阅读

对ArrayList集合里面数据排序

先说下原因,最近项目中出现了获取网络数据混乱的情况,经过仔细查看才知道是加入集合的顺序出了问题,由于我是循环获取id,然后再循环请

Spring mvc ContextLoaderListener 原理解析

对于熟悉Spring MVC功能,首先应从web.xml 开始,在web.xml 文件中我们需要配置一个监听器 ContextLoaderListener,如下。 <!-- 加载

Spring的ContextLoaderListener加载上下文的源码分析

前言: 1,如果使用自定义的监听器,需要经过下面的步骤 1到步骤10 2,如果使用Spring自己的监听器ContextLoaderListener,需要经过下面的

android基础--ListView 详解

1.简单的ListView       在List列表中如果不存在过于复杂的东西 我们可以直接去new ArrayAdapter() 来绘制列表,无须继承Arra

Android近期任务列表Recent List(Recents Screen)的实现

一、明确android的近期任务是什么:我们的手机下方一般有三个键,一个是返回键,中间的是home键,另一个是RecentList键,也就是最近浏览记

分享到:

栏目导航

推荐阅读

热门阅读