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 ...
随机推荐
- (转) Hibernate注解开发
http://blog.csdn.net/yerenyuan_pku/article/details/70162268 Hibernate注解开发 在Hibernate中我们一般都会使用注解,这样可以 ...
- Python 之beautifulSoup4解析库
一.节点选择器 from bs4 import BeautifulSoup if __name__ == '__main__': html = ''' <div> <ul> & ...
- 在oninitdialog后添加初始化变量
需要 UpdateData(FALSE); 刷新界面 不然有时会不显示.
- chrome浏览器 快捷键设置
如何设置谷歌浏览器在新窗口中打开链接?如何设置谷歌浏览器在新标签页中打开链接?一.快捷键方式: 1.左键单击 ==> 在当前窗口中打开目标网页. 2.Shift + 左键单击 ==> 在新 ...
- 【转】关于JMeter线程组中线程数,Ramp-Up Period,循环次数之间的设置概念
关于JMeter线程组中线程数,Ramp-Up Period,循环次数之间的设置概念 笔者是个刚刚踏入压力测试领域不到2个月的小菜,这里分享一下线程组中3个参数之间关系的个人见解,不喜请!喷!,望大家 ...
- @FunctionalInterface
>> 函数式接口也称为SAM接口 Single Abstract Method interfaces 接口有且仅有一个抽象方法 允许定义静态方法 允许定义默认方法 允许java.lang. ...
- Beauty of Array ZOJ - 3872(思维题)
Edward has an array A with N integers. He defines the beauty of an array as the summation of all dis ...
- SprinMVC接收参数乱码解决篇
1.Spring 默认的字符编码格式为iso-8859-1,为此Spring专门提供了字符过滤器org.springframework.web.filter.CharacterEncodingFilt ...
- isset在php5.6-和php7.0+的一些差异
今天在公司实现一个模块功能时写了如下代码: class ProductCategory { const TYPES = [ 1 => 'type1', 2 => 'type2', ]; p ...
- 【Codeforces Global Round 1 C】Meaningless Operations
[链接] 我是链接,点我呀:) [题意] 给你一个a 让你从1..a-1的范围中选择一个b 使得gcd(a^b,a&b)的值最大 [题解] 显然如果a的二进制中有0的话. 那么我们就让选择的b ...