zoukankan      html  css  js  c++  java
  • (搜索) poj 3700

    Missile Defence System
    Time Limit: 3000MS   Memory Limit: 65536K
    Total Submissions: 4284   Accepted: 1012

    Description

    To play against the threats of malicious countries nearby, Country R has updated their missile defence system. The new type system can bring down a series of missiles as long as they are coming in ascending order by altitude or descending order by altitude.

    Given the heights of a sequence of coming missiles, the general wants to know how many sets of the new type systems are needed to bring down all of them.

    Input

    The input consists of several test cases. The first line of each test case contains an integer n(1 ≤ n ≤ 50). The next line contains n different integers indicating the heights.

    Output

    For each test case output a single line containing the number of systems needed.

    Sample Input

    5
    3 5 2 4 1
    0 

    Sample Output

    2

    Hint

    Two sets of systems are needed for the sample. One brings down 3, 4 and the other brings down 5, 2, 1.

    Source

     
    题意:
     
    就是求 最少有几个递增序列和递减序列
     
    解析。。。
    数据这么少。。直接搜索啊。。。。
     
    dfs(x,y,t)x个递增序列,y个递减序列
     
    然后胡乱搞就好了。。。
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<algorithm>
    #include<cstdlib>
    #include<queue>
    #include<vector>
    #include<set>
    #include<stack>
    #include<map>
    #define INF 100000000
    using namespace std;
    int up[55],down[55];
    int n,a[55],ans;
    void dfs(int x,int y,int t)
    {
        if(x+y>=ans)
            return ;
        if(t>n)
        {
            if(x+y<ans)
                ans=x+y;
            return ;
        }
        int i,temp;
        for(i=1;i<=x;i++)
        {
            if(up[i]<a[t])
                break;
        }
        temp=up[i];
        up[i]=a[t];
        dfs(max(i,x),y,t+1);
        up[i]=temp;
        for(i=1;i<=y;i++)
        {
            if(down[i]>a[t])
                break;
        }
        temp=down[i];
        down[i]=a[t];
        dfs(x,max(i,y),t+1);
        down[i]=temp;
    }
    int main()
    {
        while(scanf("%d",&n)!=EOF)
        {
            if(n==0)
                break;
            for(int i=1;i<=n;i++)
                scanf("%d",&a[i]),up[i]=0,down[i]=0;
            ans=INF;
            dfs(0,0,1);
            printf("%d
    ",ans);
        }
        return 0;
    }
    

      

  • 相关阅读:
    Spark的协同过滤.Vs.Hadoop MR
    IAAS: IT公司去IOE-Alibaba系统构架解读
    八种Docker容器开发模式解析
    Docker的特性解析
    Docker的官网在线--中文教程
    三维重建:深度相机方案对比-KinectFusion的基本原理(尺度)
    ES: 机器学习、专家系统、控制系统的数学映射
    算法设计之—常用算法之-分支界定法
    图像特征综述
    CaptCha的现状与未来
  • 原文地址:https://www.cnblogs.com/water-full/p/4505958.html
Copyright © 2011-2022 走看看