hdu1515
来源:互联网 发布:工业软件具体是什么 编辑:程序博客网 时间:2024/06/06 02:50
蒟蒻的自我拯救。。。
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <stack>#include <vector>using namespace std;char st[1000],re[1000];int len,ans[1000],tmp[1000],len2;void print(){ for(int i=0;i<2*len;i++) { if(ans[i]==1) { printf("i "); } else { printf("o "); } } printf("\n");}void dfs(int pos , stack<char>ess , vector<char>pr,int num){ if(pos==len*2) { print(); return; } if(num<len) { ess.push(st[num]); int k=ans[pos]; ans[pos]=1; dfs(pos+1,ess,pr,num+1); ans[pos]=k; ess.pop(); } if(!ess.empty()) { char ch=ess.top(); if(ch==re[pr.size()]) { pr.push_back(ch); ess.pop(); int k=ans[pos]; ans[pos]=2; dfs(pos+1,ess,pr,num); ans[pos]=k; ess.push(ch); pr.pop_back(); } }}int main(){ while(scanf("%s%s",st,re)!=EOF) { stack<char>s1; vector<char>v1; len=strlen(st); len2=strlen(re); if (len < len2) { printf("[\n]\n"); continue; } printf("[\n"); dfs(0,s1,v1,0); printf("]\n"); } return 0;}
0 0
- hdu1515
- 卡特兰-HDU1515-HDU2067
- 第一个DFS,第一个递归 HDU1515
- hdu1515 Anagrams by Stack
- UVALive5369 UVa732 HDU1515 ZOJ1004 Anagrams by Stack【DFS+堆栈】
- Linux sleep命令使用方法详解
- C++11(及现代C++风格)和快速迭代式开发
- cmd.exe简单指令
- 英数字输入规则等
- (字母二叉树) B - Falling Leaves(10.1.2))
- hdu1515
- 黑马程序员 java学习笔记——String类(包含StringBuffer和StringBuilder)
- python c/s 聊天
- 费用报销过程中可能出现的问题
- iOS开发控件之UISegmentedControl:基本属性与自定义
- 使用libcurl下载网络数据存储到数据库(使用libcurl和sqlite数据库)
- 原型设计工具的对比评测记录(一)
- istringstream用法
- CSDN 排名第2,3,6的 大神