当前位置: 首页 > news >正文

POJ 3134 - Power Calculus

迭代加深

//Twenty
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
int n,num[1000],lim;
int dfs(int cnt,int x) {
    if(num[cnt]==n) return 1;
    if(cnt>=lim) return 0;
    x=max(x,num[cnt]);
    if(x*(1<<(lim-cnt))<n) return 0;
    for(int i=0;i<=cnt;i++) {
        num[cnt+1]=num[cnt]+num[i];
        if(dfs(cnt+1,x)) return 1;
        if(num[cnt]>num[i]) 
        num[cnt+1]=num[cnt]-num[i];
        else num[cnt+1]=num[i]-num[cnt];
        if(dfs(cnt+1,x)) return 1;
    }
    return 0;
} 
int main()
{
    for(;;) {
        scanf("%d",&n);
        if(!n) break;
        if(n==1)  printf("0\n");
        else{
            num[0]=1;
            for(lim=1;;lim++) 
                if(dfs(0,1)) break;   
             printf("%d\n",lim);
        }
    }
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/Achenchen/p/7507168.html

相关文章:

  • hdu 6201 transaction transaction transaction
  • java的(PO,VO,TO,BO,DAO,POJO)解释
  • Cent OS服务器配置(JDK+Tomcat+MySQL)
  • python库基础练习
  • 可以直接cat 多个fq.gz压缩文件
  • 条件、循环、函数定义 练习
  • 深入学习微框架:Spring Boot
  • 原创:mysql下载 实战 最强最全的无脑白痴版 给小白的爱
  • sql语句执行碰到的问题
  • 数据类型和运算符
  • JSP中文乱码问题
  • shell脚本进阶(二)
  • ServiceLoader的使用
  • PHP的memory_limit引起的问题
  • 详解Oracle DELETE和TRUNCATE 的区别
  • Google 是如何开发 Web 框架的
  • 《Java8实战》-第四章读书笔记(引入流Stream)
  • 230. Kth Smallest Element in a BST
  • Linux编程学习笔记 | Linux IO学习[1] - 文件IO
  • Spring技术内幕笔记(2):Spring MVC 与 Web
  • tensorflow学习笔记3——MNIST应用篇
  • Tornado学习笔记(1)
  • Web Storage相关
  • windows-nginx-https-本地配置
  • 从伪并行的 Python 多线程说起
  • 道格拉斯-普克 抽稀算法 附javascript实现
  • 动态规划入门(以爬楼梯为例)
  • 容器化应用: 在阿里云搭建多节点 Openshift 集群
  • 如何优雅地使用 Sublime Text
  • 使用putty远程连接linux
  • 通信类
  • 微信小程序开发问题汇总
  • 想写好前端,先练好内功
  • #QT(串口助手-界面)
  • #stm32整理(一)flash读写
  • $HTTP_POST_VARS['']和$_POST['']的区别
  • ()、[]、{}、(())、[[]]命令替换
  • (C#)Windows Shell 外壳编程系列4 - 上下文菜单(iContextMenu)(二)嵌入菜单和执行命令...
  • (PHP)设置修改 Apache 文件根目录 (Document Root)(转帖)
  • (WSI分类)WSI分类文献小综述 2024
  • (附源码)springboot家庭财务分析系统 毕业设计641323
  • (论文阅读11/100)Fast R-CNN
  • (万字长文)Spring的核心知识尽揽其中
  • (幽默漫画)有个程序员老公,是怎样的体验?
  • (原創) 是否该学PetShop将Model和BLL分开? (.NET) (N-Tier) (PetShop) (OO)
  • (轉)JSON.stringify 语法实例讲解
  • ./configure、make、make install 命令
  • .NET 6 Mysql Canal (CDC 增量同步,捕获变更数据) 案例版
  • .NET Core 中插件式开发实现
  • .NET Core 中的路径问题
  • .NET MVC第三章、三种传值方式
  • .NET 服务 ServiceController
  • .NET6使用MiniExcel根据数据源横向导出头部标题及数据
  • .net经典笔试题
  • .Net下的签名与混淆