【POJ 3700】 Missile Defence System
【题目链接】
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的更多相关文章
- 【POJ 3140】 Contestants Division(树型dp)
id=3140">[POJ 3140] Contestants Division(树型dp) Time Limit: 2000MS Memory Limit: 65536K Tot ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
随机推荐
- 使用Sql Server Management Studio 2008将数据导出到Sql文件中
最近需要将一个Sql Server 2005数据库中的数据导出,为了方便,就希望能导出成Sql文件,里面包含的数据是由Insert 语句组成的. 在Sql Server Management St ...
- 【SQL】CASE与DECODE
1. case..when case..when语句用于按照条件返回查询结果,如当我们想把emp表的工资按照多少分成几个不同的级别,并分别统计各个级别的员工数.SQL语句如下: select (cas ...
- MatLab之Simulink之simple model
Use Simulink to model a system and then simulate the dynamic behavior of that system. 1 Open in Comm ...
- SLAM:飞行机器人的参数解析-分类
在水电站存在的山区,公路运输效率极低,盘山公路绕行消耗大量时间,使用飞行机器人进行运输是合适的选择. 实现一位长辈在山区飞行的愿望,任重而道远 常见飞行机器人的参数解析:解读飞行机器人的基本类型及技术 ...
- mvc登录授权特性
public class CommonAuthorize : AuthorizeAttribute { protected override bool AuthorizeCore(HttpContex ...
- 雪花算法生成全局唯一ID
系统中某些场景少不了全局唯一ID的使用,来保证数据的唯一性.除了通过数据库自带的自增id来保证 id 的唯一性,通常为了保证的数据的可移植性会选择通过程序生成全局唯一 id.百度了不少php相关的生成 ...
- NOIp2016-NOIp2011解题报告(骗分)
zxl钦点.让我练暴力骗分. 那就把2016-2011年的题目搞一搞. NOIp2016 Day1 T1 AC 100pts. (妈呀,这么水的一道题竟然还要调试,一遍过不了样例,果然是要退役的节奏啊 ...
- 09.正则表达式re-3.常用的匹配规则
模式 描述 \w 匹配字母.数字及下划线 \W 匹配不是字母.数字及下划线的字符 \s 匹配任意空白字符,等价于[\t\n\r\f] \S 匹配任意非空字符 \d 匹配任意数字,等价于[0-9] \D ...
- <a>标签中的href伪协议 标签: html 2016-12-24 22:38 365人阅读 评论(0)
<a id="jsPswEdit" class="set-item" href="javascript:;">修改密码</ ...
- 6.在idea中链接数据库
1.打开数据库配置的窗口 File - view - Tool Windows - Database 2.打开mysql的数据库链接模板 Database - + - Data Source - M ...