题目链接。

分析:

这题从早上调到现在。也不算太麻烦,细节吧。

每个数字都只有两种状态,加入前一序列和不加入前一序列。DFS枚举。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <string>
#include <queue> using namespace std; int ord[], len, ans_a[], tar, max_ans, cnt;
char s[];
bool flag; void dfs(int cur_s, int cur_t, int cur) {
if(cur_s+cur_t > tar) { // error
return ;
}
else if(cur == len) { //
int t = cur_s + cur_t;
if(t > tar) return ;
else if(t > max_ans) {
cnt = ;
max_ans = t;
memcpy(ans_a, ord, sizeof(ord));
}
else if(t == max_ans) {
cnt++;
}
flag = true;
return ;
} ord[cur] = ;
dfs(cur_s+cur_t+s[cur]-'', , cur+); if(cur != len-) {
ord[cur] = ;
dfs(cur_s, (cur_t+s[cur]-'')*, cur+);
}
} int main() {
int n;
// freopen("my.txt", "r", stdin); while(scanf("%d %d", &tar, &n) == && (n | tar)) {
flag = false;
max_ans = ; cnt = ; sprintf(s, "%d", n);
len = strlen(s); dfs(, , ); if(!flag) printf("error\n");
else if(cnt >= ) printf("rejected\n");
else {
printf("%d", max_ans);
int sn=;
for(int i=; i<len; i++) {
if(ans_a[i] == ) {
printf(" %d", sn*+s[i]-'');
sn = ;
}
else {
sn = sn*+s[i]-'';
}
} putchar('\n');
}
} return ;
}

POJ1416 Shredding Company(dfs)的更多相关文章

  1. POJ1416——Shredding Company(DFS)

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

  2. poj1416 Shredding Company

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

  3. poj 1416 Shredding Company( dfs )

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

  4. Shredding Company(dfs)

    http://poj.org/problem?id=1416 题意:将一个数分成几部分,使其分割的各个数的和最大并且小于所给的数. 凌乱了..参考的会神的代码..orz... #include < ...

  5. Shredding Company(dfs)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3519   Accepted: 2009 Description You h ...

  6. POJ 1416 Shredding Company【dfs入门】

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

  7. Shredding Company (hdu 1539 dfs)

    Shredding Company Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  8. POJ 1416 Shredding Company 回溯搜索 DFS

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

  9. 搜索+剪枝 POJ 1416 Shredding Company

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

随机推荐

  1. ios从相册:摄像头中获取视频

    ios从相册/摄像头中获取视频 如何从相册中获取视频 使用的是一个和获取照片相同的类UIImagePickerController //相册中获取视频 - (IBAction)clickViedoOF ...

  2. [转] JavaScript中的属性:如何遍历属性

    在JavaScript中,遍历一个对象的属性往往没有在其他语言中遍历一个哈希(有些语言称为字典)的键那么简单.这主要有两个方面的原因:一个是,JavaScript中的对象通常都处在某个原型链中,它会从 ...

  3. CakePHP之控制器

    控制器 控制器是MVC中的“C”. 如果你的网站使用Cake框架制作,一般根据url地址和通过路由,就会找到正确的控制器,然后控制器的动作就会被调用. 一个控制器需要解释请求数据.确保使用正确的模型. ...

  4. 一个初学者对CLSA.NET框架的使用心得

    什么是CSLA.NET框架? 今天在一个群里,有人问我什么是CSLA.NET,CSLA是Component-based, Scalable, Logical Architecture的简写,CSLA ...

  5. C#模拟POST提交表单(二)--HttpWebRequest以及HttpWebResponse

    上次介绍了用WebClient的方式提交POST请求,这次,我继续来介绍用其它一种方式 HttpWebRequest以及HttpWebResponse 自认为与上次介绍的WebClient最大的不同之 ...

  6. Long型整数,缄默溢出

    /** 长整数问题 @author husky */ public class LongDemo { public static void main(String[] args) { /** * 问题 ...

  7. SetTimer 和 OnTimer 的使用

    最近在公司做一个MFC项目,因为是MFC新手,所以在这里记录一些最近用到和学到的东西留着以后查阅. 今天遇到的一个问题是要在窗口刚刚初始化完成时自动检测一个配置文件是否存在(实际上就是检测是不是首次登 ...

  8. SGU 188.Factory guard

    模拟 code #include <iostream> #include <cstdio> #define LEN 1000 using namespace std; int ...

  9. mysql如何将一个表导出为excel表格

    方法一:进入到mysql的控制台,输入: 1. SELECT * INTO OUTFILE ‘./test.xls‘ FROM tb1 WHERE 1 ORDER BY id DESC  LIMIT ...

  10. nginx插件ngx_lua

    ngx_lua是淘宝的维护的产品,真心不错.配置文件包含可以做很多事情的lua脚本. 公司有个产品对注册的广告盒子进行反向代理,这样可以在盒子上做很多事情:和服务器通信,远程控制盒子等等.nginx反 ...