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 ...
随机推荐
- php环境扩展包so
http://files.cnblogs.com/files/adtuu/no-debug-non-zts-20121212.zip /Applications/XAMPP/xamppfiles/li ...
- win10 安装scrapy
在win10的环境下安装scrapy,并不能直接按照官网的手册(http://doc.scrapy.org/en/1.0/intro/install.html)一次性安装成功,根据我自己的安装过程中遇 ...
- 1076. Forwards on Weibo (30)
时间限制 3000 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Weibo is known as the Chinese v ...
- hdu 4622 Reincarnation SAM模板题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4622 题意:给定一个长度不超过2000的字符串,之后有Q次区间查询(Q <= 10000),问区 ...
- ExtJs 4.2 treePanel 点击树节点 传送参数到后台(多个参数)
//***********************************************左边树开始********************************************** ...
- c#对字符串的各种操作
1.字符串定义 2.在字符串后面追加字符串 3.获取字符串长度 4.截取字符串的一部分 5.字符串转为比特码 6.查指定位置是否为空字符 7.查字符串是否是标点符号 8.截头去尾(Trim) 9.替换 ...
- 5.3:从bean的实例中获取对象
5.3 从bean的实例中获取对象 在getBean方法中,getObjectForBeanInstance是个高频率使用的方法,无论是从缓存中获得bean还是根据不同的scope策略加载bean. ...
- 团体程序设计天梯赛-练习集L1-003. 个位数统计
L1-003. 个位数统计 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定一个k位整数N = dk-1*10k-1 + . ...
- The 6th Zhejiang Provincial Collegiate Programming Contest->ProblemA:Second-price Auction
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3202 题意:拍卖东西,以第二高价的价格卖给出第一高价的人.输出最后获得东西 ...
- ADO.net--杂七杂八(一)
private void BtnConnectDataBase_Click(object sender, RoutedEventArgs e) { string connectionString = ...