hdu1515

44 篇文章 0 订阅
蒟蒻的自我拯救。。。
#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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值