【题目链接】

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. 自动换行 word-break:break-all和word-wrap:break-word

    1.word-break:break-all;当内容(比如很长的一个单词)到每行的末端时,它会把单词截断显示一部分,下一行显示后一部分. 2.word-wrap:break-word;当内容(比如很长 ...

  2. Spring boot -环境搭建 ,初步接触(1)

    1. Eclipse 创建 maven project  项目目录如下: 2. pom.xml  配置文件 <project xmlns="http://maven.apache.or ...

  3. Leetcode0100--Same Tree 相同树

    [转载请注明]http://www.cnblogs.com/igoslly/p/8707664.html 来看一下题目: Given two binary trees, write a functio ...

  4. 使用CMD建立指定格式的文件

    一.建立空文件的几种方法1.cd.>a.txtcd.表示改变当前目录为当前目录,即等于没改变:而且此命令不会有输出.>表示把命令输出写入到文件.后面跟着a.txt,就表示写入到a.txt. ...

  5. 省市区县的sql语句——省

    /*SQLyog v10.2 MySQL - 5.5.48 : Database - 省市县****************************************************** ...

  6. SQL Server2008优化之SET STATISTICS开关

    一.准备工作 缓存对于某个查询的性能影响十分之大,所以优化之前要清空缓存. 清除Buffer Pool时面的所有缓存 DBCC DROPCLEANBUFFERS清除Buffer Pool里的所有缓存的 ...

  7. ASP.NET Cache 实现依赖Oracle的缓存策略

    ASP.NET 中的缓存提供了对SQL依赖项的支持,也就是说当SQL SERVER数据库中的表或行中的数据被更改后,缓存中的页面就失效,否则,页面输出可一直保留在缓存当中.这确实为程序员提供了方便.但 ...

  8. Deutsch lernen (01)

    Was macht Martin? - Um 8.00 Uhr steht martin auf. aufstehen - aufstand - ist aufgestanden 起床 Um 6 Uh ...

  9. 使用Reporting Services时遇到的小问题

    同事忙不开了交过来的一个小问题,以前我也没有做过Reporting Services相关的. 大概看了一下,是数据集那边的查询代码接收不到报表参数,而且不是单纯地接收不到,具体情况如下.. 命令类型是 ...

  10. HTML编辑器ASP.NET

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="kindeditor.aspx. ...