【题目链接】

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 ; }

最新文章

  1. Java魔法堂:类加载机制入了个门
  2. .net 动态代理的泛型方法支持问题
  3. [LINUX] 查看连接数和IO负载
  4. 【翻译】Kinect v2程序设计(C++) Color篇
  5. Hadoop和大数据:60款顶级大数据开源工具
  6. 【redis】03list类型
  7. textContent、innerText的用法,在文档中插入纯文本
  8. JS 实现取整(二)
  9. ios7新特性3-Map Kit新特性
  10. optimize performance
  11. 【HDOJ】2645 find the nearest station
  12. Laravel-数据库操作笔记
  13. eclipse配置自动提示EXTJS和jQurey
  14. IP:网际协议
  15. java基础知识拾遗(四)
  16. 大白话Vue源码系列目录
  17. Css3关键帧动画
  18. 51nod 1387 移数字
  19. HTB Linux queuing discipline manual - user guide笔记
  20. Vue 中提示报错 handlers[i].call is not a function解决方法

热门文章

  1. swift-delegate(代理)或者block传值
  2. 【转载】【翻译】JavaScript Scoping and Hoisting--JS作用域和变量提升的探讨
  3. CSS的常用属性(三)
  4. wamp中的mysql服务与原来安装的mysql服务冲突的解决办法
  5. sqlserver 常用到的架构相关的表芝士
  6. vsftp服务器搭建
  7. 解析python部分常用魔术方法
  8. 单点登录之 CAS SSO 从入门到精通(第一天)
  9. 一张图搞懂javascript原型链
  10. GDB调试工具、动态加载、内存管理(day04)