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 ...
随机推荐
- android112 jni 把java的字符串转换成c的字符串,数组处理
package com.itheima.charencode; import android.os.Bundle; import android.app.Activity; import androi ...
- kcachegrind gui for callgrind
DocumentationScreenshotsDownload/SourcesLinksRoadmapBugs & Wishes This is the homepage of the pr ...
- 谈谈JSON数据格式
JSON 是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,是理想的数据交换格式. 本文主要是对JS操作JSON的要领做下总结. 在JSON中,有两种结构:对 ...
- Mac通过以太网共享网络
在日常工作和学习中,需要WiFi热点而没有路由器,这个时候我们可以用我们工作的Mac来共享网络. 系统偏好设置->共享->互联网共享:设置共享来源和共享端口->WiFi选项:设置网络 ...
- C++ notes for beginners(2)
作者:马 岩(Furzoom) (http://www.cnblogs.com/furzoom/)版权声明:本文的版权归作者与博客园共同所有.转载时请在明显地方注明本文的详细链接,未经作者同意请不要删 ...
- YII中路径别名
路径别名 system:代表framework目录 system.web:代表framework/web目录 zii:代表framework/zii目录 webroot:代表项目下的app目录(htt ...
- Nginx+Tomcat+memcached负载均衡实现session共享
http://blog.csdn.net/love_ubuntu/article/details/8464983 1. 安装各个软件不用说了. 2. 到tomcat的安装目录lib中,加入: me ...
- git研究2
git也有发布版本时期的tag,不过这个tag,主要是作为一个标记而存在的,或者说在某个commit上面再打一个标记,表明版本是多少.这个和SVN上面的不太一样,SVN感觉有多份保存,似乎没有git方 ...
- Lucene/Solr开发经验
1.开篇语2.概述3.渊源4.初识Solr5.Solr的安装6.Solr分词顺序7.Solr中文应用的一个实例8.Solr的检索运算符 [开篇语]按照惯例应该写一篇技术文章了,这次结合Lucene/S ...
- 关于添加非系统framework后,import导入头文件时没有提示的解决办法
##1.选择target(就是左边你的工程target)—— BuildSettings —— search Paths 下的 User Header Search Paths(如图所示: ##2.双 ...