POJ1416 Shredding Company(dfs)
题目链接。
分析:
这题从早上调到现在。也不算太麻烦,细节吧。
每个数字都只有两种状态,加入前一序列和不加入前一序列。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)的更多相关文章
- POJ1416——Shredding Company(DFS)
Shredding Company DescriptionYou have just been put in charge of developing a new shredder for the S ...
- poj1416 Shredding Company
Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5379 Accepted: 3023 ...
- poj 1416 Shredding Company( dfs )
我的dfs真的好虚啊……,又是看的别人的博客做的 题目== 题目:http://poj.org/problem?id=1416 题意:给你两个数n,m;n表示最大数,m则是需要切割的数. 切割m,使得 ...
- Shredding Company(dfs)
http://poj.org/problem?id=1416 题意:将一个数分成几部分,使其分割的各个数的和最大并且小于所给的数. 凌乱了..参考的会神的代码..orz... #include < ...
- Shredding Company(dfs)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3519 Accepted: 2009 Description You h ...
- POJ 1416 Shredding Company【dfs入门】
题目传送门:http://poj.org/problem?id=1416 Shredding Company Time Limit: 1000MS Memory Limit: 10000K Tot ...
- Shredding Company (hdu 1539 dfs)
Shredding Company Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- POJ 1416 Shredding Company 回溯搜索 DFS
Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6173 Accepted: 3361 ...
- 搜索+剪枝 POJ 1416 Shredding Company
POJ 1416 Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5231 Accep ...
随机推荐
- Android 6.0 Changes
原文链接:http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html 伴随着新特性和功能,Andr ...
- Java基础知识强化之集合框架笔记22:List集合的三个子类的特点(面试题)
1. List:(面试题List的子类特点)(1)ArrayList: 底层数据结构是数组,查询快,增删慢. 线程不安全,效率高.(2)Vector: 底层数据结构是数组,查询快,增删慢. 线程安全, ...
- Java基础知识强化之集合框架笔记21:数据结构之 数组 和 链表
1. 数组 2. 链表
- Objective-C:swift、objective-c、C++、C混合编程
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css); @import url(/ ...
- ubuntu环境配置之vi 配置【转载】
ubuntu环境配置之vi 配置 [日期:2014-02-10] 来源:Linux社区 作者:zhonghe1114 [字体:大 中 小] Android的源码开发,几乎离不开Linux,Lin ...
- Python之路【第十篇】:HTML -暂无等待更新
Python之路[第十篇]:HTML -暂无等待更新
- php获得访问来源(手机wap访问、电脑web访问)
为了更好的用户体验,本主题默认支持wap和web两种访问样式,wap访问将不包含任何脚本.样式也是重新撰写,不支持更多页面,只支持首页.详情页, 评论框.登录等内容将陆续更新到wap内容里.如果想测试 ...
- CSS3 变形小结
为原始大小 b:纵向扭曲,0为不变 c :横向扭曲,0不变 d:垂直伸缩量,1为原始大小 e:水平偏移量,0为初始位置 f :垂直偏移向,0是初始位置 Ø原点 transform-origin() ...
- Linux gvim windows 版本配置
http://www.cnblogs.com/xiekeli/archive/2012/08/13/2637176.html 资源在我的网盘里面
- java编程思想-异常
DynamicFields类的setField方法里面的getField方法抛出的异常NoSuchFieldException 为什么是throw new RuntimeException(e);