【题目链接】

http://poj.org/problem?id=3700

【算法】

对于每一枚导弹,有4种决策 :

1.新建一套递增的系统拦截它

2.新建一套递减的系统拦截它

3.在已经建好的递增拦截系统中任选一个符合条件的拦截

4.在已经建好的递减拦截系统中任选一个符合条件的拦截

如果直接搜索,复杂度显然太高,考虑剪枝 :

1.贪心地思考这个问题,我们发现如果能用已经建好的系统拦截,那么就不需要新建了,如果有递增的符合条件的系统,在这些系统中选最近拦截高度最高的,如果有递减的符合条件的系统,在这些系统中选最近拦截高度最低的

2.显然答案是很小的,每枚导弹至少可以和另一枚导弹“配对”,用一套系统拦截,因此最劣情况下也只需25套拦截系统,不妨使用迭代加深算法

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std; int i,n,tota,totb,step;
int a[],b[],h[]; inline bool dfs(int dep)
{
int i,mx,mn,pos,tmp;
if (tota + totb > step) return false;
if (dep > n) return true;
pos = ; mx = ;
for (i = ; i <= tota; i++)
{
if (a[i] < h[dep] && a[i] > mx)
{
mx = a[i];
pos = i;
}
}
if (pos)
{
tmp = a[pos];
a[pos] = h[dep];
if (dfs(dep+)) return true;
a[pos] = tmp;
} else
{
tota++;
a[tota] = h[dep];
if (dfs(dep+)) return true;
tota--;
}
pos = ; mn = 2e9;
for (i = ; i <= totb; i++)
{
if (b[i] > h[dep] && b[i] < mn)
{
mn = b[i];
pos = i;
}
}
if (pos)
{
tmp = b[pos];
b[pos] = h[dep];
if (dfs(dep+)) return true;
b[pos] = tmp;
} else
{
totb++;
b[totb] = h[dep];
if (dfs(dep+)) return true;
totb--;
}
return false;
} int main()
{ while (scanf("%d",&n) && n)
{
for (i = ; i <= n; i++) scanf("%d",&h[i]);
for (i = ; i <= n; i++)
{
memset(a,,sizeof(a));
memset(b,,sizeof(b));
tota = totb = ;
step = i;
if (dfs())
{
printf("%d\n",i);
break;
}
}
} return ; }

【POJ 3700】 Missile Defence System的更多相关文章

  1. 【POJ 3140】 Contestants Division(树型dp)

    id=3140">[POJ 3140] Contestants Division(树型dp) Time Limit: 2000MS   Memory Limit: 65536K Tot ...

  2. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  3. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  4. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  5. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  6. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  7. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  8. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

  9. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

随机推荐

  1. html5与css3入门知识点精炼

    <meta name = "keywords" content="…………"/>(网页搜索时要输入的关键字) <meta name = &qu ...

  2. js-事件处理(重点)

    1:各种常用事件: 2:简单用法: <body onLoad="javascript:alert('hello world');" onUnload="javasc ...

  3. 【SQL】结构化查询语言

    一:数据查询语言(DQL:Data Query Language): 其语句,也称为“数据检索语句”,用以从表中获得数据,确定数据怎样在应用程序给出.保留字SELECT是DQL(也是所有SQL)用得最 ...

  4. oracle从入门到精通复习笔记

    为方便大家跟着我的笔记练习,为此提供数据库表文件给大家下载:点我下载 描述一个表用 desc employees过滤重复的部门 select distinct department_id from e ...

  5. C#屏蔽Alt+F4,解决Alt+F4关闭窗体时对话框NO后,线程不退出问题

    //1.将窗体的属性KeyPrieview设置为true //keypreview属性为true的时候,就可以响应键盘事件v //2.在窗体KeyDown事件中加如下代码 private void F ...

  6. 点云处理软件Pointscene

    转载于PCL中国:点云处理软件Pointscene 软件官网:https://pointscene.com/ 笔者评:        Pointscene是目前的点云处理软件之一,其主要是操作简单直观 ...

  7. Day3 分支结构

    if语句的使用 在Python中,要构造分支结构可以使用if.elif和else关键字.所谓关键字就是有特殊含义的单词,像if和else就是专门用于构造分支结构的关键字,很显然你不能够使用它作为变量名 ...

  8. C#第十三节课

    冒泡排序 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System. ...

  9. Hibernate事务管理-HibernateTransactionManager-对hibernate session的管理

    由于对SSH还停留在比较初级的应用水平上,今天在遇到一个疑惑时折腾了很久,具体问题是这样的, 有这么一个测试方法, public static void test1() { ApplicationCo ...

  10. 9.Spring的IOC+MyBaits+log4j+Servlet

    1.创建如下mysql脚本 drop table if exists book_info; create table if not exists book_info( book_id ) primar ...