HNUOJ 13341
来源:互联网 发布:淘宝男模特王梓亦 编辑:程序博客网 时间:2024/06/03 19:06
题目给你一个串, 串是严格的 1 – n 的排列,里面的数是随机的
把这个串里面的数字分别输出//先预处理,对于给出的串能找到里面的最大数,再 DFS 处理
#include<iostream>#include<string>#include<algorithm>#include<cstdio>#include<cstring>#include<stack>using namespace std;bool Jug[100];string num[55]; string str;int len,Num;stack<int> Sum;bool Dfs(int n) { if(n >= len) { if(Jug[Num] == true) return true; return false; } int a,b; if(n <len) a = str[n] - '0'; if(n < len-1) b = a*10 + str[n+1] - '0'; if(a==0) return false; if(Jug[a] == false && n <len) { Jug[a] = true; if(Dfs(n+1)) { Sum.push(a); return true; } Jug[a] = false; } if(b <= 50 && Jug[b] == false && n < len-1) { Jug[b] = true; if(Dfs(n+2)) { Sum.push(b); return true; } Jug[b] = false; } return false;}int main() { num[1] = "1"; for(int i = 2; i <= 50; ++i) if(i < 10) num[i] = (num[i-1] + char(i + '0')); else num[i] = (num[i-1] + char(i/10 + '0') + char (i % 10 + '0')); for(int i = 1; i <= 50; ++i) sort(num[i].begin(),num[i].end()); ////////////// while(cin >> str) { Num = 0; memset(Jug,false,sizeof(Jug)); while(!Sum.empty()) Sum.pop(); string s = str; sort(s.begin(),s.end()); for(int i = 1; i <= 50; ++i) if(s == num[i]) { Num = i; break; } //cout << Num << endl; len = str.length(); Dfs(0); while(!Sum.empty()) { cout << Sum.top() << " "; Sum.pop(); } cout << endl;}}
0 0
- HNUOJ 13341
- dp hnuoj
- hnuoj 13103 Easy Delete
- hnuoj 字典树 map c++
- HNUOJ 13309 Intrepid climber(搜索)
- hnuoj 13377 Book Club(匈牙利算法)
- hnuoj 13375 Flowery Trails(SPFA)
- hnuoj LRU Caching (链表,结构体指针 / vector)
- ZOJ 2971 && HNUOJ 16490 Give Me the Number
- hnuoj 13313 Smoking gun(SPFA+拓扑序)
- HNUOJ 12609 统计单词 2013年“程序之星”ACM程序设计大赛(水题一A纪念)
- iOS使用ASCII码和NSScanner字符扫描来判断关于键盘限制输入
- java中volatile关键字的含义
- 你知道 Linux 内核是如何构建的吗?
- cellForRowAtIndexPath与willDisplayCell的区别
- Find Lines
- HNUOJ 13341
- HDU 5288 OO’s Sequence
- HDU 5289
- HDU 5297
- POJ 2115
- HDU 1573
- HDU 3579
- Java代码优化--尽可能地使用stack(栈)变量(方法内部的局部变量)
- POJ 3243 // HDU 2815(改下输出,加个判断)