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 ( a1a2, ..., aN) be any sequence ( ai1ai2, ..., 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;
}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值