首页 > 其他 > 详细

hdu 1274 展开字符串 (简单dfs)

时间:2015-01-22 17:40:32      阅读:181      评论:0      收藏:0      [点我收藏+]

http://acm.hdu.edu.cn/showproblem.php?pid=1274

 

思路: 找到匹配的区间 之后dfs

 

技术分享
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
char str[300];
void dfs(int l,int r)
{
    int i,j,k;
    int tl,tr,coun;
    for(i=l;i<=r;i++)
    {
        if(str[i]<=9&&str[i]>=0)
        {
            coun=str[i]-0;
            tr=tl=i+1;
            if(str[tl]==()
            {
              int tcnt=1;
              for(j=tl+1;j<=r;j++)
              {
                if(str[j]==() tcnt++;
                else if(str[j]==)) tcnt--;
                if(tcnt==0) {tr=j;break;}
              }
            }
            for(j=1;j<=coun;j++)
            {
                dfs(tl,tr);
                i=tr; continue;
            }
        }
        else if(str[i]<=z&&str[i]>=a)
        {
            printf("%c",str[i]);
        }
    }
}
int main()
{
    int n;
    int i,j,k;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%s",str);
        int len=strlen(str);
        dfs(0,len-1);
        printf("\n");
    }
    return 0;
}
View Code

 

hdu 1274 展开字符串 (简单dfs)

原文:http://www.cnblogs.com/sola1994/p/4241914.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!