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 ...
随机推荐
- discuz random函数
在研究邮箱非必填的过程中发现了个比较好用的random函数,在function_core.php中找到声明: function random($length, $numeric = 0) { $see ...
- net发布mvc项目
1.复制 Web 文件夹 2.复制 DLL 文件C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies C ...
- mvc 之 @Html.DropDownList
Dictionary<string, string> myDic = new Dictionary<string, string>(); myDic.Add(System.DB ...
- 从浏览器启动应用程序 - Application URL
关键字:Browser,Application,URL Protocol,Windows,Mac,IE,Chrome,Safari. OS: Windows 7, OS X Yosemite. Win ...
- .htaccess 设置
RewriteEngine on RewriteCond %{HTTP_HOST} ^blog.chosenet.com$RewriteCond %{REQUEST_URI} !^/blog/Rew ...
- EXTJS 4.2 资料 控件之checkboxgroup的用法(动态数据)
在开发中遇到两种情况:第一在新增窗体时,要动态加载CheckBox项:第二在修改时不但需要加载所有CheckBox项,还要并且选中之前新增时的选项 如图这是在修改页面的效果: 1.在新增窗体中动态加载 ...
- 用于软件包管理的21个Linux YUM命令
FROM:http://os.51cto.com/art/201309/411895.htm YUM(Yellowdog Updater Modified)是一款开源命令行及图形化软件包管理工具,面向 ...
- CQRS学习——最小单元的Cqrs(CommandEvent)[其一]
[说明:博主采用边写边思考的方式完成这一系列的博客,所以代码以附件为准,文中代码仅为了说明.] 结构 在学习和实现CQRS的过程中,首要参考的项目是这个[http://www.cnblogs.com/ ...
- [转载]Log4net学习笔记
Log4net 学习笔记: 主要是根据apache站点整理的: 原文链接:http://logging.apache.org/log4net/release/sdk/ http://logging.a ...
- PAT-乙级-1026. 程序运行时间(15)
1026. 程序运行时间(15) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 要获得一个C语言程序的运行时间, ...