Shredding Company(dfs)
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)的更多相关文章
- POJ1416——Shredding Company(DFS)
Shredding Company DescriptionYou have just been put in charge of developing a new shredder for the S ...
- poj 1416 Shredding Company( dfs )
我的dfs真的好虚啊……,又是看的别人的博客做的 题目== 题目:http://poj.org/problem?id=1416 题意:给你两个数n,m;n表示最大数,m则是需要切割的数. 切割m,使得 ...
- POJ1416 Shredding Company(dfs)
题目链接. 分析: 这题从早上调到现在.也不算太麻烦,细节吧. 每个数字都只有两种状态,加入前一序列和不加入前一序列.DFS枚举. #include <iostream> #include ...
- Shredding Company(dfs)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3519 Accepted: 2009 Description You h ...
- POJ 1416 Shredding Company【dfs入门】
题目传送门:http://poj.org/problem?id=1416 Shredding Company Time Limit: 1000MS Memory Limit: 10000K Tot ...
- Shredding Company (hdu 1539 dfs)
Shredding Company Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- POJ 1416 Shredding Company 回溯搜索 DFS
Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6173 Accepted: 3361 ...
- poj1416 Shredding Company
Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5379 Accepted: 3023 ...
- 搜索+剪枝 POJ 1416 Shredding Company
POJ 1416 Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5231 Accep ...
随机推荐
- js输出非字符串,非null值
console.log(!"");//非空(true) console.log(!);//非0(true) console.log(!" ");//非空格(fa ...
- Gorgeous Sequence 题解 (小清新线段树)
这道题被学长称为“科幻题” 题面 事实上,并不是做法科幻,而是“为什么能这么做?”的解释非常科幻 换句话说,复杂度分析灰常诡异以至于吉如一大佬当场吃书 线段树维护的量:区间和sum,区间最大值max1 ...
- Ansible 利用playbook批量部署Nginx
我这里直接部署的,环境已经搭建好,如果不知道的小伙伴可以看上一遍ansible搭建,都写好了,这里是根据前面环境部署的 192.168.30.21 ansible 192.168.30.25 ...
- HDU3336Count the string
HDU3336Count the string Problem Description It is well known that AekdyCoin is good at string proble ...
- discourse论坛迁移
在源设备的操作备份数据文件tar -czvf discoursefile716.tar.gz /var/discourse然后把此discoursefile716.tar.gz文件传到需要迁移的设备上 ...
- 【郑轻邀请赛 G】密室逃脱
[题目链接]:https://acm.zzuli.edu.cn/zzuliacm/problem.php?id=2133 [题意] [题解] 考虑每一个二进制数的最高位->第i位; 肯定是1(这 ...
- nyoj_8_一种排序_201311251238
一种排序 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 现在有很多长方形,每一个长方形都有一个编号,这个编号可以重复:还知道这个长方形的宽和长,编 ...
- linux 内核视频-英本网
01.Linux内核学习入门 http://v.youku.com/v_show/id_XNjc1NzEzODAw.html02.Linux内核介绍 http:// ...
- GDB 调试 PHP文件
http://www.bo56.com/%E5%9C%A82016%E7%9A%84phpcon%E5%A4%A7%E4%BC%9A%E4%B8%8A%E7%9A%84%E5%88%86%E4%BA% ...
- Clojure:将两个list合并成一个map
假设我们有两个list,分别是: (def a [“one” “two” “three”]) (def b [1 2 3]) 我们要把它们合为一个键值对应的map,做法很简单: 1. 先将a和b合为一 ...