zoukankan      html  css  js  c++  java
  • UVA529 Addition Chains

    //迭代加深
    //UVA529 Addition Chains  P110 Addition
    #include <iostream>
    #include <cstdio>
    #include <vector>
    #include <map>
    #include <algorithm>
    #include <cstring>
    #include <queue>
    #include <set>
    #include <cmath>
    
    #define ll long long
    //#define File
    #define ull unsigned long long
    
    using namespace std;
    
    const int N=17;
    const int M=100000+10;
    const int MOD=1e9+7;
    const double PI = acos(-1.0);
    const double EXP = 1E-8;
    const int INF = 0x3f3f3f3f;
    
    int n;int a[N];int depth;bool f;
    
    void iddfs(int d)
    {
        if(d>depth){
            if(a[d-1]==n) f = 1;
            return;
        }
        for(int i=0;i<d;i++){
            for(int j=0;j<d;j++){
                if(a[i]+a[j]>a[d-1] && a[i]+a[j]<=n && !f){
                    a[d] = a[i]+a[j];
                    int t = a[d];t=t<<(depth - d);
                    if(t < n) continue;
                    iddfs(d+1);
                }
            }
        }
    }
    
    int
    main()
    {
        #ifdef File
            //freopen(, , stdin);
            //freopen(, , stdout);
        #endif
        a[0]=1;a[1]=2;
        while(scanf("%d",&n)!=EOF && n!= 0){
            if(n==1) {printf("1
    ");continue;}
            if(n==2) {printf("1 2
    ");continue;}
            f = false ; depth = 1;
            while(!f){
                iddfs(2);
                depth++;
            }
            for(int i=0;i<depth;i++) printf("%d ",a[i]);
            printf("
    ");
        }
        return 0;
    }
    
  • 相关阅读:
    JSON和JSONP
    微信问题汇总
    Linux 技巧:让进程在后台可靠运行的几种方法
    redis笔记
    php安装
    数据库分享一: MySQL的Innodb缓存相关优化
    nginx是以多进程的方式来工作的
    运行和控制Nginx
    nginx安装
    Redis监控技巧总结
  • 原文地址:https://www.cnblogs.com/axchml/p/13777562.html
Copyright © 2011-2022 走看看