POJ--1416
#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的更多相关文章
- 搜索+剪枝 POJ 1416 Shredding Company
POJ 1416 Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5231 Accep ...
- POJ 1416 Shredding Company【dfs入门】
题目传送门:http://poj.org/problem?id=1416 Shredding Company Time Limit: 1000MS Memory Limit: 10000K Tot ...
- poj 1416 Shredding Company( dfs )
我的dfs真的好虚啊……,又是看的别人的博客做的 题目== 题目:http://poj.org/problem?id=1416 题意:给你两个数n,m;n表示最大数,m则是需要切割的数. 切割m,使得 ...
- OpenJudge 2803 碎纸机 / Poj 1416 Shredding Company
1.链接地址: http://poj.org/problem?id=1416 http://bailian.openjudge.cn/practice/2803 2.题目: 总时间限制: 1000ms ...
- POJ 1416 Shredding Company
题目: http://poj.org/problem?id=1416 又16ms 1A了,这人品... #include <stdio.h> #include <string.h&g ...
- poj 1416 (hdu 1539)Shredding Company:剪枝搜索
点击打开链接 题目大意是有一个分割机,可以把一串数字分割成若干个数字之后求和,题目输入一个数字上界和待分割的数字,让我们求出分割后数字之和在不超过给定max的情况下的最大值,并且给出分割方案,如果没有 ...
- 【POJ 1416】Shredding Company
题 题意 给你一个target number,和一个最多六位的数num,让你把数分段,使总和最接近但不大于target number. 如果只有一种方法就输出总和.分段,如果有多种方法,输出rejec ...
- hdu 1539 & poj 1416 某某公司
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1539 大意是输入n和m,把m按顺序拆分成若干个数,问这些数和的在小于n的前提下最大为多少 注意必须m的 ...
- POJ 1416 Shredding Company 回溯搜索 DFS
Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6173 Accepted: 3361 ...
- POJ 1416 DFS
题目翻译: 公司现在要发明一种新的碎纸机,要求新的碎纸机能够把纸条上的数字切成最接近而不超过target值.比如,target的值是50,而纸条上的数字是12346,应该把数字切成四部分,分别是1.2 ...
随机推荐
- SQL Server 2012 Enterprise Core Edition和SQL Server 2012 Enterprise Edition的区别
core没有图形界面,只有power shell界面,给没有图形界面的windows用的.
- ExtJS 4.2 中自定义事件
前台HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www ...
- 你不知道的JavaScript 二
词法作用域 上次说到作用域,将其定义为一套规则,这套规则用来管理引擎如何在当前作用 域以及嵌套的子作用域中根据标识符名称进行变量查找. 作用域共有两种主要的工作模型.第一种是最为普遍的,被大多数编程语 ...
- cookie、session、sessionid 与jsessionid
可查看 http://www.cnblogs.com/fnng/archive/2012/08/14/2637279.html
- TesCase-GUI(图形用户界面)测试
GUI测试是功能测试的一种表现形式.不仅要考虑GUI本身的测试,也要考虑GUI所表现的系统功能的测试. GUI应具有的要素 1.符合标准和规范 2.直观性 (1)用户界面是否洁净.不唐突.不拥挤? ...
- [翻译]你真的知道你看到的UTF-8字符是什么吗?
翻译自http://www.pixelstech.net/article/1397877200-You-know-what-UTF-8-is-when-you-see-it- Source : son ...
- Select的深入应用(2)
首先创建两张表. 全连接 全连接:在检索时指定多个表,将每个表用逗号分隔,这样每个表的数据行都和其他表的每行交叉产生所有可能的组合,这样就是一个全连接.所有可能的组和数即每个表的行数的乘积. 或者: ...
- -(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
在有全屏侧滑的情况下,页面上有个slider需要左右滑动的时候,经常在滑动slider的时候页面也跟着滑动 解决办法一:关闭当前页面的全屏侧滑,开启系统侧滑 self ...
- Android 操作系统的内存回收机制
参考 http://www.ibm.com/developerworks/cn/opensource/os-cn-android-mmry-rcycl/index.html
- 关于BitmapFactory解析流的问题a
今天碰到了一个超级恶心的问题,BitmapFactory.decodeStream(bis,null,options)一直是返回NULL 问题是这样子的: InputStream is= respon ...