• 【IOI 1994】 The Buses


    【题目链接】

               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 = 1; i <= g; i++)
            {
                    if (b[i].opt == 1)
                            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]] <= 0) return IDDFS(dep+1,m);
            for (i = 1; i <= m; i++)
            {
                    if (b[i].opt == 1)
                    {
                            d = a[dep] - b[i].fir;
                            if (d <= b[i].fir) continue;
                            b[i].opt = 2;
                            tmp = a[dep];
                            while (tmp <= mx && h[tmp] > 0)
                            {
                                    h[tmp]--;
                                    tmp += d;        
                            }    
                            if (tmp > mx) 
                            {
                                    if (IDDFS(dep+1,m)) 
                                            return true;
                            }
                            b[i].opt = 1;
                            e = tmp - d;
                            tmp = a[dep];
                            while (tmp <= e)
                            {
                                    h[tmp]++;
                                    tmp += d;
                            }
                    }
            }
            if (m >= g) return false;
            if (2 * a[dep] >= 59) return false;
            m++;
            h[a[dep]]--;
            b[m].opt = 1;
            b[m].fir = a[dep];
            if (IDDFS(dep+1,m)) 
                    return true;
            h[a[dep]]++;
            return false;
    }
    
    int main() 
    {
            
            scanf("%d",&n);
            for (i = 1; i <= n; i++) 
            {
                    scanf("%d",&a[i]);
                    if (a[i] > mx)
                            mx = a[i];
                    h[a[i]]++;
            }
            for (i = 1; i <= 17; i++)
            {
                    g = i;
                    if (IDDFS(1,0))
                            break;        
            }
            printf("%d
    ",g);
            
            return 0;
        
    }
  • 相关阅读:
    Zend Framework 项目 index.php 的问题
    《MySQL 必知必会》读书总结
    phpstorm 无法格式化代码
    Windows 下 zip 版的 MySQL 的安装
    配置Windows下的PHP开发环境
    phpstorm 激活服务器
    《DOM Scripting》
    《JavaScript高级程序设计》
    sql 查找所有已经分配部门的员工
    sql 表的连接 inner join、full join、left join、right join、natural join
  • 原文地址:https://www.cnblogs.com/evenbao/p/9279439.html
Copyright © 2020-2023  润新知