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 ...
随机推荐
- springMVC项目引入jstl标签库若干问题的总结
中午,不知道动到项目的哪个地方了,之前在联系人列表页面用的好好的jstl标签库突然报错了:<%@taglib prefix="c" uri="http://java ...
- Redis学习手册(Hashes数据类型)
一.概述: 我们可以将Redis中的Hashes类型看成具有String Key和String Value的map容器.所以该类型非常适合于存储值对象的信息.如Username.Password和Ag ...
- [linux]date命令时间戳和时间之间的转换
非常多时候我们查看数据库的数据,或者是一些别人系统中的数据须要用时间戳来查询.或者查询出来的结果是个时间戳. 还有时候,查询条件须要输入时间戳. 我之前的办法就是用在线工具来完毕,后来用mac了.我觉 ...
- HDU1016(bfs)
import java.util.Scanner;public class Main1016 { public static void main(String[] args) { Scanner ci ...
- iOS项目进行测试的配置
一.首先,注册苹果开发者账号并登陆https://developer.apple.com/account/#/overview/ZFBE9NJZM6, 二.创建测试证书
- JavaScript跨域解决办法
在找到跨域解决办法之前,我们要先弄清楚一些基本概念 什么是跨域? 什么是“同源策略”? 跨文档消息通信 & 跨域请求数据 主域相同而子域不同 不同域名的跨域访问 什么是跨域? 简单地理解就是因 ...
- [转]前端开发必备 40款优秀CSS代码编写工具推荐
编写工具地址如下 英文地址:http://webtoolsdepot.com/40-css-tools-to-improve-your-productivity/ 中文地址:http://www.cs ...
- git github 使用教程
参考文章:文章地址: http://wuyuans.com/2012/05/github-simple-tutorial/ github是一个基于git的代码托管平台,付费用户可以建私人仓库,我们一般 ...
- java经验总结二:ORA-08103: 对象不再存在
问题发生的环境: 在springMvc+mybatis框架中,调用oracle的存储过程时,碰到的一个这样的异常: org.springframework.jdbc.UncategorizedSQLE ...
- 0基础学习ios开发笔记第二天
C语言的基本结构 c语言的入口函数是main函数. main函数的返回值行业标准是int return 数字:返回值 每条语句最后以分号结尾 注释:行注释.块注释 int main(void) { / ...