http://poj.org/problem?id=1416

题意:将一个数分成几部分,使其分割的各个数的和最大并且小于所给的数。

凌乱了。。参考的会神的代码。。orz...

 #include <stdio.h>
#include <string.h> int arr[],ans[];
int max,len,f;
int a,b; void dfs(int n,int now,int sum,int k,int t)
{
int m = n % ;
if (!n)
{
arr[k] = now;
if (sum + now > a)
return ;
if (sum + now ==max)
f++;
if (sum +now > max)
{
max = sum + now;
f = ;
len = k;
for (int i = ; i <= k; i ++)
{
ans[i] = arr[i];
} }
return ;
}
dfs(n/,now+t*m,sum,k,t*);
arr[k] = now;
dfs(n/,m,sum+now,k+,);
}
int main()
{
while(~scanf("%d%d",&a,&b)&&a&&b)
{
max = ;
f = ;
dfs(b/,b%,,,);
if (max==)
{
printf("error\n");
continue;
}
if (f > )
{
printf("rejected\n");
continue;
}
printf("%d",max);
for (int i = len; i >= ; i --)
{
printf(" %d",ans[i]);
}
printf("\n");
}
return ;
}

Shredding Company(dfs)的更多相关文章

  1. POJ1416——Shredding Company(DFS)

    Shredding Company DescriptionYou have just been put in charge of developing a new shredder for the S ...

  2. poj 1416 Shredding Company( dfs )

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

  3. POJ1416 Shredding Company(dfs)

    题目链接. 分析: 这题从早上调到现在.也不算太麻烦,细节吧. 每个数字都只有两种状态,加入前一序列和不加入前一序列.DFS枚举. #include <iostream> #include ...

  4. Shredding Company(dfs)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3519   Accepted: 2009 Description You h ...

  5. POJ 1416 Shredding Company【dfs入门】

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

  6. Shredding Company (hdu 1539 dfs)

    Shredding Company Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  7. POJ 1416 Shredding Company 回溯搜索 DFS

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

  8. poj1416 Shredding Company

    Shredding Company Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5379   Accepted: 3023 ...

  9. 搜索+剪枝 POJ 1416 Shredding Company

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

随机推荐

  1. 转:LINQ教程一:LINQ简介

    原文地址:https://www.cnblogs.com/dotnet261010/p/8278793.html 一.为什么要使用LINQ 要理解为什么使用LINQ,先来看下面一个例子.假设有一个整数 ...

  2. Django - ORM创建基本类

    DBFirst CodeFirst 创建类 1.根据类自动创建数据库表 在app下的models.py中创建表 创建数据库之前,需要在django下的setting.py模块中的INSTALLED_A ...

  3. perf-perf stat用户层代码分析

    perf_event 源码分析 前言 简单来说,perf是一种性能监测工具,它首先对通用处理器提供的performance counter进行编程,设定计数器阈值和事件,然后性能计数器就会在设定事件发 ...

  4. gitlab分享项目到其它组

    1. 找到以下页面(管理员权限),随便点入一个项目 2. 点击edit编辑 3.点击members 4. 查看是否分享成功

  5. OSI 7层模型和 TCP/IP 5层模型

    网络协议通常分不同层次进行开发,每一层分别负责不同的通行功能. 两种参考模型 OSI 和 TCP/IP, OSI 先有模型后有协议,TCP/IP 则相反. OSI 7层模型 - 应用层 - 表示层 - ...

  6. 49.ardinality算法之优化内存开销以及HLL算法

    主要知识点 precision_threshold参数的理解 HLL算法优化(hash)         cardinality,count(distinct),5%的错误率,性能在100ms左右   ...

  7. 7.2.1 代码测试 doctest

    Python标准库 doctest 可以搜索程序中类似于交互式Python代码的文本片段,并运行这些交互式代码来验证是否符合预期结果和功能,常用于Python程序的模块测试. 使用doctest模块测 ...

  8. time库

    简介 返回系统当前时间戳(正常的生活时间) 返回格林威治时间戳对应的struct_time对象 本地时间的struct_time对象 当前时间戳对应的易读格式字符串时间(周几,月份,号数,时,分,秒, ...

  9. hibernate之一对多映射

    目录 第一章 课程简介 第二章 Hibernate中的单向一对多关联 2-1 一对多映射简介 2-2 hibernate的基础配置 2-3 创建HibernateUtil工具类 2-4 在mysql数 ...

  10. svn重新定位或checkout,提示输入用户名密码,输入后报错

    在MyEclipse中,source——>clean up.然后重新定位或checkout