#include <stdio.h>
#include <stdlib.h> int data[]={};//代表有没有切割的数组
int input=;//输入的要被切割的数字
int output[]={};//切完输出的数组成的数组
int a[]={};
int count=;
int final;
int target=;
int best[]={};//用于存储最优的切割方法
int max=;
bool findpath = ; //计算目标和最终和的差值
void handle(int final,int target){
int chazhi;
chazhi = target - final;
if(chazhi<max){
max = chazhi;
}
//把最优的切割方法存储起来
for(int i=;i<;i++){
best[i] = data[i];
}
}
void func(int step){
if(step==) {//先假设数字有五位
//计算
findpath =;
//1==12345/(data[0]*10*(位数-1))
for(int i=;i>;i--){
if(data[i]==)//代表需要切割
{
int num=;
for(int j=;j<i;j++){
num =num*;
}
a[count] = input%num;//余数就是切割后面的数
input = input/num;
count ++;
}
} for(int k=;k<count;k++)
{
final += a[k];
}
handle(final,target);
return;
}
data[step] = ;
func(step+); data[step] = ;
func(step+); }
int main(){
func();
printf("%d",findpath);
for(int i=;i<;i++){
printf("%d\n",best[i]);
}
system("pause");
}

POJ--1416的更多相关文章

  1. 搜索+剪枝 POJ 1416 Shredding Company

    POJ 1416 Shredding Company Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5231   Accep ...

  2. POJ 1416 Shredding Company【dfs入门】

    题目传送门:http://poj.org/problem?id=1416 Shredding Company Time Limit: 1000MS   Memory Limit: 10000K Tot ...

  3. poj 1416 Shredding Company( dfs )

    我的dfs真的好虚啊……,又是看的别人的博客做的 题目== 题目:http://poj.org/problem?id=1416 题意:给你两个数n,m;n表示最大数,m则是需要切割的数. 切割m,使得 ...

  4. OpenJudge 2803 碎纸机 / Poj 1416 Shredding Company

    1.链接地址: http://poj.org/problem?id=1416 http://bailian.openjudge.cn/practice/2803 2.题目: 总时间限制: 1000ms ...

  5. POJ 1416 Shredding Company

    题目: http://poj.org/problem?id=1416 又16ms 1A了,这人品... #include <stdio.h> #include <string.h&g ...

  6. poj 1416 (hdu 1539)Shredding Company:剪枝搜索

    点击打开链接 题目大意是有一个分割机,可以把一串数字分割成若干个数字之后求和,题目输入一个数字上界和待分割的数字,让我们求出分割后数字之和在不超过给定max的情况下的最大值,并且给出分割方案,如果没有 ...

  7. 【POJ 1416】Shredding Company

    题 题意 给你一个target number,和一个最多六位的数num,让你把数分段,使总和最接近但不大于target number. 如果只有一种方法就输出总和.分段,如果有多种方法,输出rejec ...

  8. hdu 1539 & poj 1416 某某公司

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1539 大意是输入n和m,把m按顺序拆分成若干个数,问这些数和的在小于n的前提下最大为多少 注意必须m的 ...

  9. POJ 1416 Shredding Company 回溯搜索 DFS

    Shredding Company Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6173   Accepted: 3361 ...

  10. POJ 1416 DFS

    题目翻译: 公司现在要发明一种新的碎纸机,要求新的碎纸机能够把纸条上的数字切成最接近而不超过target值.比如,target的值是50,而纸条上的数字是12346,应该把数字切成四部分,分别是1.2 ...

随机推荐

  1. 传输层(一)TCP的三次握手和四次挥手及关闭套接字的原理

    TCP连接需三次握手才能建立,断开连接则需要四次握手. 客户端TCP状态迁移: CLOSED->SYN_SENT->ESTABLISHED->FIN_WAIT_1->FIN_W ...

  2. 将Excel中数据导入数据库(二)

    在上篇文章中介绍到将Excel中数据导入到数据库中,但上篇文章例子只出现了nvachar类型,且数据量很小.今天碰到将Excel中数据导入数据库中的Excel有6419行,其中每行均有48个字段,有i ...

  3. makefile 学习(一)

    一.Makefile的基本规则 GNU make 规则: target ... : prerequisites ...     command     ....     .... target - 目 ...

  4. windows内核对象可以等待

    内核对象有两种状态 触发 与未触发. 是可以等待的.

  5. SVN与TortoiseSVN实战:文件加锁详解

    硬广:<SVN与TortoiseSVN实战>系列已经写了八篇,本篇是完结篇,整个系列结合TortoiseSVN对SVN中容易被忽视的部分进行了详解,以技巧性为主. 本篇详解使用Tortoi ...

  6. JS跳转到顶部的方法

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>J ...

  7. JavaScript 性能优化1

    一直在学习javascript,也有看过<犀利开发Jquery内核详解与实践>,对这本书的评价只有两个字犀利,可能是对javascript理解的还不够透彻异或是自己太笨,更多的是自己不擅于 ...

  8. ON DUPLICATE KEY UPDATE用法

    INSERT INTO `books ` (`name`,`count`,`num`) VALUES ('windows','1','2'),('','linux','1','3') ON DUPLI ...

  9. leetcode 121

    121. Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of ...

  10. XSS测试语句大全

    '><script>alert(document.cookie)</script> ='><script>alert(document.cookie)& ...