• 防卫导弹


    时限:1000ms 内存限制:10000K  总时限:3000ms

    描述
    一种新型的防卫导弹可截击多个攻击导弹。它可以向前飞行,也可以用很快的速度向下飞行,可以毫无损伤地截击进攻导弹,但不可以向后或向上飞行。但有一个缺点,尽管它发射时可以达到任意高度,但它只能截击比它上次截击导弹时所处高度低或者高度相同的导弹。现对这种新型防卫导弹进行测试,在每一次测试中,发射一系列的测试导弹(这些导弹发射的间隔时间固定,飞行速度相同),该防卫导弹所能获得的信息包括各进攻导弹的高度,以及它们发射次序。现要求编一程序,求在每次测试中,该防卫导弹最多能截击的进攻导弹数量,一个导弹能被截击应满足下列两个条件之一:
    a)它是该次测试中第一个被防卫导弹截击的导弹;
    b)它是在上一次被截击导弹的发射后发射,且高度不大于上一次被截击导弹的高度的导弹。
     
    输入
    多个测例。
    每个测例第一行是一个整数n(n不超过100),第二行n个整数表示导弹的高度(数字的顺序即发射的顺序)。
    n=0表示输入结束。
     
    输出
    每个测例在单独的一行内输出截击导弹的最大数目。
     
    输入样例
    5
    5 6 100 6 61
    0
     
    输出样例
    2
     
    /*
    * @author  Panoss
    */
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<vector>
    #include<ctime>
    #include<stack>
    #include<queue>
    #include<list>
    using namespace std;
    #define DBG 1
    #define fori(i,a,b) for(int i = (a); i < (b); i++)
    #define forie(i,a,b) for(int i = (a); i <= (b); i++)
    #define ford(i,a,b) for(int i = (a); i > (b); i--)
    #define forde(i,a,b) for(int i = (a); i >= (b); i--)
    #define forls(i,a,b,n) for(int i = (a); i != (b); i = n[i])
    #define mset(a,v) memset(a, v, sizeof(a))
    #define mcpy(a,b) memcpy(a, b, sizeof(a))
    #define dout  DBG && cerr << __LINE__ << " >>| "
    #define checkv(x) dout << #x"=" << (x) << " | "<<endl
    #define checka(array,a,b) if(DBG) { 
        dout << #array"[] | " << endl; 
        forie(i, a, b) cerr << "[" << i << "]=" << array[i] << " |" << ((i - (a)+1) % 5 ? " " : "
    "); 
    if (((b)-(a)+1) % 5) cerr << endl; 
    }
    #define redata(T, x) T x; cin >> x
    #define MIN_LD -2147483648
    #define MAX_LD  2147483647
    #define MIN_LLD -9223372036854775808
    #define MAX_LLD  9223372036854775807
    #define MAX_INF 18446744073709551615
    inline int  reint() { int d; scanf("%d", &d); return d; }
    inline long relong() { long l; scanf("%ld", &l); return l; }
    inline char rechar() { scanf(" "); return getchar(); }
    inline double redouble() { double d; scanf("%lf", &d); return d; }
    inline string restring() { string s; cin >> s; return s; }
    
    int h[105];
    int f[105];     ///f[i] 表示为选择截击的第i个导弹,从这个导弹开始最多能截击的导弹数目
    
    int DP(int n)
    {
        mset(f,0);
        f[n] = 1;   ///初始化截击最后一枚导弹,最多只能截击一枚
        int ans_max = 0;
        forde(i,n-1,1)
        {
            //checkv(i);
            int MAX = 0;
            forie(j,i+1,n)
            {
                if(h[j] <= h[i] && MAX < f[j])
                {
                    MAX = f[j];
                    //checkv(MAX);
                    //checkv(j);
                    //checkv(f[j]);
                }
            }
            f[i] = MAX + 1;
            ans_max = max(ans_max,f[i]);
        }
        return ans_max;
    }
    int main()
    {
        int n;
        while(scanf("%d",&n)==1&&n)
        {
            forie(i,1,n)
                scanf("%d",&h[i]);
            cout << DP(n) << endl;
        }
    }
  • 相关阅读:
    oracle 自定义字符串分割函数split()
    oracle 创建md5函数
    eclipse 纯java项目如果导入外部jar包?
    tomcat server.xml标签功能详解
    oracle 根据汉字生成首字母简拼(助记码)
    IDEA的注解自动成了中文,怎么恢复正常
    @TransactionalEventListener 之Spring的事务监听器
    Git fork常用方法
    Mapstruct源码解析 框架实现原理
    Git提交到其他分支了,需要把其他分支上的部分commit迁回cherrypick
  • 原文地址:https://www.cnblogs.com/Panoss/p/3779095.html
Copyright © 2020-2023  润新知