【题目链接】

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. Android 权限管理(持续整理)

    1. Android 6.0之后,APP可以直接安装,运行时再询问用户授予相关权限,此时系统弹出一个对话框,(这个对话框不能由开发者定制) 同时用户也可以在手机的“设置”中对于某个App进行权限管理 ...

  2. MVC返回400 /404/...

    return new HttpStatusCodeResult(HttpStatusCode.BadRequest); //HttpStatusCode statusCode 枚举 // HttpSt ...

  3. 集合运算(UNION)

    表的加法 集合运算:就是满足统一规则的记录进行的加减等四则运算. 通过集合运算可以得到两张表中记录的集合或者公共记录的集合,又或者其中某张表中记录的集合. 集合运算符:用来进行集合的运算符. UNIO ...

  4. 移动端mui常用方法

    本文分享一些用Mui的时候所采的坑 1.mui中上拉刷新事件a标签中的链接.元素onclick事件在手机上点击不了 mui('body').on('tap','a',function(){docume ...

  5. python时间序列按频率生成日期

    有时候我们的数据是按某个频率收集的,比如每日.每月.每15分钟,那么我们怎么产生对应频率的索引呢?pandas中的date_range可用于生成指定长度的DatetimeIndex.我们先看一下怎么生 ...

  6. 绝对好用的浏览器json解析网址

    你们是否经常在浏览器输入请求地址解析遇到中文乱码的情况,今天我找到了一个好用的浏览器解析json网址,绝对好用. 1.直接输入网址 http://pro.jsonlint.com/ 2.输入要解析的j ...

  7. CSS设置input默认样式

    HTML <ul class="box"> <li> <input type="checkbox" name="vehi ...

  8. Linux C(day01)

    Linux是一个和Windows类似的操作系统 通常通过终端软件使用Linux操作系统 终端软件里只能使用键盘不能使用鼠标 可以在终端软件里输入各种命令控制计算机 完成各种任务 clear命令可以清除 ...

  9. 教你如何检查一个函数是否为JavaScript运行时环境内建函数

    在开发过程中,对于某些API在现有的JavaScript运行时环境不支持的时候,我们大都会采用加入polyfill来解决这个问题.但有些时候我们可能需要知道现在某个API到底是否为运行时环境所原生支持 ...

  10. win安装配置Java8环境

    这里就不重复造轮子,搜索一下. 一堆就出来 这里就引用一个百度知道的经验 https://jingyan.baidu.com/article/48b558e3f135687f38c09a03.html ...