题目链接

分析:

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

每个数字都只有两种状态,加入前一序列和不加入前一序列。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. div css背景图片不显示

    我们在写页面时,为了便于维护,css样式通常都是通过link外部导入html的,有时在css中写入背景图片时,此时背景图片的路径应该是相对css文件的.比如,此时的文件有index.html,css. ...

  2. ubuntu环境配置之vi 配置【转载】

    ubuntu环境配置之vi 配置 [日期:2014-02-10] 来源:Linux社区  作者:zhonghe1114 [字体:大 中 小]   Android的源码开发,几乎离不开Linux,Lin ...

  3. Oracle中wm_concat()的使用方法

    以下两种方式使用wm_concat()的使用方法是等效的. 方法一:使用窗口函数,wm_concat支持窗口函数 select distinct classKey,className, classOr ...

  4. 解决mybatis使用枚举的转换

    解决mybatis使用枚举的转换 >>>>>>>>>>>>>>>>>>>>> ...

  5. 每次打开VS2010都会报“ devenv.exe -Assert Failure”这个错误

    把.net framework4.5中文包卸载掉,, 如果还不行就把.net framework4.5也卸载掉,,然后到微软官网下载net framework4.5安装包安装,安装完后把中文包卸载掉就 ...

  6. [Redis] windows下安装 Redis

    一:Redis是什么? Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API. 通过https://github.c ...

  7. WebForm开发常用代码

    1.获取服务器绝对路径: public static string GetMapPath(string strPath) { if (HttpContext.Current != null) { re ...

  8. js自定义方法名

    自定义方法名: <script language="javascript" type="text/javascript">window.onload ...

  9. oracle中用comment on的用法

    oracle中用comment on命令给表或字段加以说明,语法如下:COMMENT ON  { TABLE [ schema. ]    { table | view }  | COLUMN [ s ...

  10. Oracle实用技巧

    一. ORACLE SQL PLUS 使用技巧: ----①查找重复记录: SELECT DRAWING, DSNOFROM EM5_PIPE_PREFABWHERE ROWID!= (SELECT ...