POJ 1416 Shredding Company
题目: http://poj.org/problem?id=1416
又16ms 1A了,这人品。。。
#include <stdio.h>
#include <string.h> int n, ans;
bool rejected;
char path[], tmp[], ans_path[]; void dfs(int sum, char s[])
{
if(sum > n)return;
if(s[] == '\0')
{
if(sum == ans)rejected = ;
else if(sum > ans && sum <= n)
{
rejected = ;
ans = sum;
strcpy(ans_path, path);
}
return;
}
int len = strlen(s);
for(int i = ; i <= len; i++)
{
int x = s[] - '';
for(int j = ; j < i; j++)
x = x * + s[j] - '';
int pathlen = strlen(path); sprintf(path, "%s %d", path, x);
//也可以把上面一行写成下面这两行。上面的写法把自己打印到自己,与编译器有关。
//sprintf(tmp, " %d", x);
//strcat(path, tmp); dfs(x+sum, &s[i]);
path[pathlen] = '\0';
}
} int main()
{
char s[];
while(scanf("%d %s", &n, s) != EOF)
{
if(n == && s[] == '')break;
ans = -;
rejected = ;
int len = strlen(s);
for(int i = ; i <= len; i++)
{
int x = s[] - '';
for(int j = ; j < i; j++)
x = x * + s[j] - '';
sprintf(path, "%d", x);
dfs(x, &s[i]);
}
if(ans == -)
printf("error\n");
else if(rejected)
printf("rejected\n");
else
printf("%d %s\n", ans, ans_path);
}
return ;
}
POJ 1416 Shredding Company的更多相关文章
- 搜索+剪枝 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 ...
- poj 1416 Shredding Company( dfs )
我的dfs真的好虚啊……,又是看的别人的博客做的 题目== 题目:http://poj.org/problem?id=1416 题意:给你两个数n,m;n表示最大数,m则是需要切割的数. 切割m,使得 ...
- 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
Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4713 Accepted: 2714 ...
- poj1416 Shredding Company
Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5379 Accepted: 3023 ...
- Shredding Company
Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4653 Accepted: 2675 Des ...
- POJ1416——Shredding Company(DFS)
Shredding Company DescriptionYou have just been put in charge of developing a new shredder for the S ...
随机推荐
- SQL Server 2008 游标使用实例
本文使用以下两张数据库表作为演示对象. 1 游标初探--使用游标进行遍历 declare @classAndStudent table( class_id int, --班级ID class_name ...
- HashMap早知道
第一眼hashmap始终Collection那个地点 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGxmMTIzMzIx/font/5a6L5L2T/f ...
- mysql优化之连接优化
Posted by Money Talks on 2012/02/23 | 第一篇 序章第二篇 连接优化第三篇 索引优化第四篇 查询优化第五篇 到实战中去 连接优化 连接优化主要指客户端连接数据库以及 ...
- “:Choose a destination with a supported architecture in order to run on this device.”
我在编译从GitHub上clone下来的<TweeJump>时,出现如下错误:":Choose a destination with a supported architectu ...
- cocos2dx shader
http://www.oschina.net/question/565065_79818 Cocos2d-x 2.0 -- 从 点,线,面学起 http://blog.csdn.net/dawn_mo ...
- C#基础篇02
首先:一个完整的方法是包括两部分的,代码和注释!!!! 程序的调试: 3:设置断点: 断点之前的程序已经确保正确,可是在断点后的部分可能出现错误,所以设置完断点后,直接点击启动,然后按F11逐步棸的 ...
- jedis应用实例
最近将redis整合到项目中,将redis作为cache使用,未来进一步作为消息推送使用.我通过jedis和spring配置实现操作redis. spring配置 <!-- redis配置 -- ...
- RazorEngine在非MVC下的使用,以及使用自定义模板
---恢复内容开始--- RazorEngine模板引擎大大的帮助了我们简化字符串的拼接与方法的调用,开源之后,现在在简单的web程序,winform程序,甚至控制台程序都可以利用它来完成. 但如何在 ...
- C#中params使用
1.参数被params修饰即为可变参数,params只能修饰一维数组. 2.给可变参数赋值的时候,可以直接传递数组的元素. 3.在调用的时候,会自动将这些元素封装为一个数组,并将数组传递. 4.可变参 ...
- Canvas实现曲线运动
前言 Html5添加的最受欢迎的功能就是<canvas>元素,它负责在页面中设定一个区域,然后在里面可以通过javascript动态地在其内绘制图形. 主流浏览器,IE9+,手机端都是支持 ...