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 ...
随机推荐
- 【转】Android 最火框架XUtils之注解机制详解
原文:http://blog.csdn.net/rain_butterfly/article/details/37931031 在上一篇文章Android 最火的快速开发框架XUtils中简单介绍了x ...
- 为一张PCI卡打通经络的过程
一张PCI卡通过“一转二”的转接卡插在主板上,probe调用失败,日志显示读取配置空间的时候发生了奇偶校验错误,可是使用相同的转接卡把它插在另外一台相同机器的主板上时,却运行正常,这就说明不是转接卡的 ...
- 原创C# 枚举 多状态 操作
C# 中枚举类型是一种值类型,目前(vs2012)还不能用于泛型. 此类型最多的用处是标识一组相同类型的状态量或常量,比如: 状态量 示例一 [Flags] public enum Connectio ...
- C#数据库读取数据后转换为INT32后计算的小技巧
这有什么难的,不管是什么数据库, 首先分别读出userinfo中usermoney的值 存入s1,card中extramoney的值s2 读出字段数据你应该会吧! 再用userinfo中字段userm ...
- “DBUtility.DbHelperSQL”的类型初始值设定项引发异常 “DBUtility.DbHelperSQL”的类型初始值设定项引发异常
今天遇到了一个这样的问题“DBUtility.DbHelperSQL”的类型初始值设定项引发异常“DBUtility.DbHelperSQL”的类型初始值设定项引发异常 也许有和我遇到这问题的人也在这 ...
- Import user's Environment path into Linux cron task
How to use "cron" to create scheduled task Minimum time cycle: 1 minute Use crontab -e edi ...
- case when then 与 count联合使用
我们都知道SQL中适用case when then来转化数据库中的信息 比如 select (case sex when 0 then '男' else '女' end) AS sex from ...
- jquery知识 内部 外部插入元素
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- T-SQL通过触发器创建级联更新·级联删除
create trigger t_table_a on table_a for update,dalete begin if exists(select 1 from inserted) update ...
- android开发者博客二月Android Studio2.0测试
参考网页-http://android-developers.blogspot.com/2016/02/android-studio-20-beta.html Android Studio 2.0-B ...