【IOI 1994】 The Buses
2024-09-07 09:13:36
【题目链接】
http://poj.org/problem?id=1167
【算法】
深度优先搜索 + 迭代加深
【代码】
#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;
#define MAXN 1010 struct info
{
int opt,fir;
} b[MAXN]; int i,n,g,mx;
int a[MAXN],h[MAXN]; inline bool check()
{
for (i = ; i <= g; i++)
{
if (b[i].opt == )
return false;
}
return true;
}
inline bool IDDFS(int dep,int m)
{
int i,d,tmp,e;
if (dep > n)
{
if (check())
return true;
else return false;
}
if (h[a[dep]] <= ) return IDDFS(dep+,m);
for (i = ; i <= m; i++)
{
if (b[i].opt == )
{
d = a[dep] - b[i].fir;
if (d <= b[i].fir) continue;
b[i].opt = ;
tmp = a[dep];
while (tmp <= mx && h[tmp] > )
{
h[tmp]--;
tmp += d;
}
if (tmp > mx)
{
if (IDDFS(dep+,m))
return true;
}
b[i].opt = ;
e = tmp - d;
tmp = a[dep];
while (tmp <= e)
{
h[tmp]++;
tmp += d;
}
}
}
if (m >= g) return false;
if ( * a[dep] >= ) return false;
m++;
h[a[dep]]--;
b[m].opt = ;
b[m].fir = a[dep];
if (IDDFS(dep+,m))
return true;
h[a[dep]]++;
return false;
} int main()
{ scanf("%d",&n);
for (i = ; i <= n; i++)
{
scanf("%d",&a[i]);
if (a[i] > mx)
mx = a[i];
h[a[i]]++;
}
for (i = ; i <= ; i++)
{
g = i;
if (IDDFS(,))
break;
}
printf("%d\n",g); return ; }
最新文章
- Java魔法堂:类加载机制入了个门
- .net 动态代理的泛型方法支持问题
- [LINUX] 查看连接数和IO负载
- 【翻译】Kinect v2程序设计(C++) Color篇
- Hadoop和大数据:60款顶级大数据开源工具
- 【redis】03list类型
- textContent、innerText的用法,在文档中插入纯文本
- JS 实现取整(二)
- ios7新特性3-Map Kit新特性
- optimize performance
- 【HDOJ】2645 find the nearest station
- Laravel-数据库操作笔记
- eclipse配置自动提示EXTJS和jQurey
- IP:网际协议
- java基础知识拾遗(四)
- 大白话Vue源码系列目录
- Css3关键帧动画
- 51nod 1387 移数字
- HTB Linux queuing discipline manual - user guide笔记
- Vue 中提示报错 handlers[i].call is not a function解决方法