poj 1416 Shredding Company( dfs )
我的dfs真的好虚啊……,又是看的别人的博客做的 题目==
题目:http://poj.org/problem?id=1416
题意:给你两个数n,m;n表示最大数,m则是需要切割的数。
切割m,使得切割之后的数的和小于等于n。
求出最大的切割方法;
例: 50 12346
12346可以切割为 1 2 34 6和为43,这个数小于n。
12346也可以切割为1 2 3 4 6和为16,这个数也小于n;
但是43大于16,所以去43而不取16;
参考博客:http://www.cnblogs.com/luyingfeng/
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<queue>
#include<iomanip>
#include<cmath>
#include<map>
#include<vector>
#include<algorithm>
using namespace std; int m,n,a[],t[];
int _max,r,ansk;
void dfs(int n,int sum,int now,int k,int p)
{
if(!n)
{
t[k]=now;
if(sum+now>m) return;
if(sum+now==_max) r++;
else if(sum+now>_max)
{
_max=sum+now;
r=;
ansk=k;
for(int i=; i<=k; i++)
a[i]=t[i];
}
return;
}
int mm=n%;
dfs(n/,sum,now+p*mm,k,p*);
t[k]=now;
dfs(n/,sum+now,mm,k+,);
}
int main()
{
while(cin>>m>>n&&(m!=||n!=))
{
_max=; r=;
dfs(n/,,n%,,);
if(_max==)
{
cout<<"error"<<endl;
continue;
}
if(r>)
{
cout<<"rejected"<<endl;
continue;
}
cout<<_max;
for(int i=ansk; i>=; i--)
cout<<" "<<a[i];
cout<<endl;
}
return ;
}
poj 1416 Shredding Company( dfs )的更多相关文章
- 搜索+剪枝 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
Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6173 Accepted: 3361 ...
- 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 ...
- POJ1416——Shredding Company(DFS)
Shredding Company DescriptionYou have just been put in charge of developing a new shredder for the S ...
- Shredding Company(dfs)
http://poj.org/problem?id=1416 题意:将一个数分成几部分,使其分割的各个数的和最大并且小于所给的数. 凌乱了..参考的会神的代码..orz... #include < ...
- POJ1416 Shredding Company(dfs)
题目链接. 分析: 这题从早上调到现在.也不算太麻烦,细节吧. 每个数字都只有两种状态,加入前一序列和不加入前一序列.DFS枚举. #include <iostream> #include ...
- POJ 1416:Shredding Company
Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4713 Accepted: 2714 ...
随机推荐
- event事件:
onabort: 图像的加载被中断onblur: 元素失去焦点onchange: 域的内容被改变onclick: 当用户点击某个对象时调用的事件句柄ondblclick: 当用户双击某个对象时调用的事 ...
- asp.net 点击按钮,页面没有任何变化,后台代码不触发
asp.net 点击按钮,页面没有任何变化,后台代码不触发 和可能是 asp.net button 缺少validationGroup 导致的,需要查看页面的validation并且让他们抛出错误信 ...
- Implement Custom Cache Dependencies in ASP.NET 1.x
Code download available at:CuttingEdge0407.exe(128 KB) Contents What's a Cache Dependency, Anyway? ...
- [牛感悟系列]JAVA(1)理解JAVA垃圾回收
理解JAVA垃圾回收的好处是什么?满足求知欲是一方面,编写更好的JAVA应用是另外一方面. 如果一个人对垃圾回收过程感兴趣,那表明他在应用程序开发领域有相当程度的经验.如果一个人在思考如何选择正确的垃 ...
- 【Google Protocol Buffer】Google Protocol Buffer
http://www.ibm.com/developerworks/cn/linux/l-cn-gpb/ Google Protocol Buffer 的使用和原理 Protocol Buffers ...
- Spring Aop实例之xml配置
AOP的配置方式有2种方式:xml配置和AspectJ注解方式.今天我们就来实践一下xml配置方式. 我采用的jdk代理,所以首先将接口和实现类代码附上 package com.tgb.aop; pu ...
- 【BZOJ 1491】 [NOI2007]社交网络
Description Input Output 输出文件包括n 行,每行一个实数,精确到小数点后3 位.第i 行的实数表 示结点i 在社交网络中的重要程度. Sample Input 4 4 1 2 ...
- VS2012编译出来的程序,在XP上运行,出现“.exe 不是有效的 win32 应用程序” “not a valid win32 application”
升级vs2010到vs2012,突然发现build出来的应用程序无法运行,提示“不是有效的 win32 应用程序” or “not a valid win32 application”. 参考CSDN ...
- [转载].Net中如何操作IIS(源代码)
///***********************************************************///************** IIS控制管理类 1.0 Beta ** ...
- (转)eclipse快捷键
Eclipse常用快捷键 Eclipse的编辑功能非常强大,掌握了Eclipse快捷键功能,能够大大提高开发效率.Eclipse中有如下一些和编辑相关的快捷键. 1. [ALT+/] 此快捷键为用户编 ...