题目: 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的更多相关文章

  1. 搜索+剪枝 POJ 1416 Shredding Company

    POJ 1416 Shredding Company Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5231   Accep ...

  2. POJ 1416 Shredding Company【dfs入门】

    题目传送门:http://poj.org/problem?id=1416 Shredding Company Time Limit: 1000MS   Memory Limit: 10000K Tot ...

  3. POJ 1416 Shredding Company 回溯搜索 DFS

    Shredding Company Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6173   Accepted: 3361 ...

  4. poj 1416 Shredding Company( dfs )

    我的dfs真的好虚啊……,又是看的别人的博客做的 题目== 题目:http://poj.org/problem?id=1416 题意:给你两个数n,m;n表示最大数,m则是需要切割的数. 切割m,使得 ...

  5. OpenJudge 2803 碎纸机 / Poj 1416 Shredding Company

    1.链接地址: http://poj.org/problem?id=1416 http://bailian.openjudge.cn/practice/2803 2.题目: 总时间限制: 1000ms ...

  6. POJ 1416:Shredding Company

    Shredding Company Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4713   Accepted: 2714 ...

  7. poj1416 Shredding Company

    Shredding Company Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5379   Accepted: 3023 ...

  8. Shredding Company

    Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4653 Accepted: 2675 Des ...

  9. POJ1416——Shredding Company(DFS)

    Shredding Company DescriptionYou have just been put in charge of developing a new shredder for the S ...

随机推荐

  1. linux中shell变量$#,$@,$0,$1,$2的含义解释

    linux中shell变量$#,$@,$0,$1,$2的含义解释 linux中shell变量$#,$@,$0,$1,$2的含义解释:  变量说明:  $$  Shell本身的PID(ProcessID ...

  2. git 设置

    系统乱码 项目中的编码统一设置为UTF-8编码. 设置系统的语言设置为 zh_UTF-8,把 export LANG=zh_CN.UTF-8 保存到~/.profile文件里. $ env|grep ...

  3. linux启动的过程

    总结一下,linux的开机整个流程. · 1: 启动电源后,主机第一步先做的就是查询BIOS(全称:basic input/output system 基本输入输出系统)信息.了解整个系统的硬件状态, ...

  4. Android App用MulticastSocket监听组播,为什么连接到不同路由、在不同手机上跑,有的能收到有的收不到

    ---------------------------!! 转载请注明出处 !!-----------------------   一个项目,利用wifi组播在局域网内发现设备.却发现在有的路由器上能 ...

  5. 第七篇:web之前端之ajax

    前端之ajax   前端之ajax 本节内容 ajax介绍 原生js实现ajax jquery实现ajax json 跨域请求 1. ajax介绍 AJAX(Asynchronous Javascri ...

  6. JS设置打印页面并调用本地打印机打印页面

    <script type="text/javascript"> var hkey_key; var hkey_root = "HKEY_CURRENT_USE ...

  7. Unity3D 之3D游戏SD快打 3D游戏基础入门开发全(1)

    这里记录一个U3D游戏,3D游戏的基本开发. 导入素材 1.首先导入需要的素材.因为FBX格式的素材是通用的,所以尽量导入这样的资源使用 导入后的结果: 然后对人形骨骼进行设置. 看哪里没有映射到骨骼 ...

  8. 20160409 javaweb 数据库连接池

    1.自己编写数据库连接池: package com.dzq.pool; import java.io.PrintWriter; import java.lang.reflect.InvocationH ...

  9. android多国语言文件夹

    android多国语言文件夹文件汇总如下:(有些语言的书写顺序可能跟中文是相反的) 中文(中国):values-zh-rCN 中文(台湾):values-zh-rTW 中文(香港):values-zh ...

  10. php安全模式

    http://www.cnblogs.com/samson/archive/2011/08/08/2130550.html php安全模式:safe_mode=on|off启用safe_mode指令将 ...