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 ...
随机推荐
- objective-c IBOutletCollection介绍
objective-c IBOutletCollection介绍 将UI控件和源码进行链接时,方法的表示方法是IBAction,控件属性对象是IBOutlet.如果想将一个同类型的UI控件作为一个组放 ...
- try、catch、finally与return
1 try catch finally语句基础知识 finally一定会被执行. try块发生异常才会执行catch块. 如果finally块中抛出异常,则整个try.catch.finally块中抛 ...
- hibernate通过判断参数动态组合Hql语句,生成基本通用查询
// public List find(Station entity) { List reuslt = null; // 字符串辅助类 StringBuffer hql = new StringBuf ...
- jquery,javascript -设置某一ul下的li下的 a的属性
//javascriptvar ul = document.getElementById('ul); var as = ul.getElementsByTagName('a'); for(var i ...
- (ternary operator)三元运算符.
ternary operator: advantage: make a terse simple conditional assignment statement of if-then-else. d ...
- EF FluentAPI映射一对多 关系时候报错
提示很明显,不可为空的外键为空了,但是 问题是,我只是初始化 关系映射而已:见代码 public ColumnsCategoryMapConfiguration() { ToTable("C ...
- Deep Learning 学习随记(六)Linear Decoder 线性解码
线性解码器(Linear Decoder) 前面第一章提到稀疏自编码器(http://www.cnblogs.com/bzjia-blog/p/SparseAutoencoder.html)的三层网络 ...
- maven mirror
国内连接maven官方的仓库更新依赖库,网速一般很慢,收集一些国内快速的maven仓库镜像以备用. ====================国内OSChina提供的镜像,非常不错=========== ...
- 将fastjson元素转化为String[]
在fastjson中如果JSONObject中添加了 String[] 类型的元素 例如 JSONObject jo = new JSONObject(); String[] array = {&qu ...
- Jquery中index()问题
对于Jquery中的index()问题,很多人会说这个很简单的,并不是一个非常困难的方法.笔者开始的时候也是这样子认为的,但是今天遇到一个index的问题,让我忙了一个晚上都没有解决,最后还是使用co ...