Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

能帮忙看一下哪里错吗?谢谢!!感觉自己思路对了,但它说错误答案,但提供的数据都测试对啊

Posted by peterk2071 at 2008-07-29 02:43:56 on Problem 1240
#include <iostream>
#include <cstring>

using namespace std;



char pre[27];
char pos[27];
int m=0;

int ary=0;

int brother[27];
int record[27];
int level=0;


int result=0;





int comp(int i)
{
    int s=-1,t=-1;
    for (int c=0;c<strlen(pre);c++)
    {
        if (pos[c]==pre[i])
        {
            s=c;
        }

        if (pos[c]==pre[i+1])
        {
            t=c;
        }

        if (t!=-1&&s!=-1)
        {
            break;
        }    

    }

    if (s-t<0)
    {
        return 0;
    }
    else
        return 1;
}



void dfs(int i)
{


    
    if (i==strlen(pre)-1)
    {
        

        for (int oo=1;oo<=level;oo++)
        {
            int tmp=1;
            for (int j=1;j<=brother[oo];j++)
            {
                tmp=tmp*(ary-j+1)/j;
                


            }
            result=result*tmp;      



        }
        return;

    }


    int ret=comp(i);



    if (ret==1)
    {
        brother[++level]++;
        record[i+1]=level;



        dfs(i+1);
        

    }
    else
    {
        int tt;
        int kk;
        int ss=0;
        int ll;

        for (ll=0;ll<strlen(pre);ll++)
        {
            if (pos[ll]==pre[i+1])
            {
                break;
            }

        }



        for (tt=ll+1;pos[tt]!='\0';tt++)
        {
            for (kk=i;kk>=0;kk--)
            {
                if (pre[kk]==pos[tt])
                {
                    ss=1;

                    break;
                }


            }

            if (ss==1)
            {
                break;
            }
        }

        int qq=record[kk]+1;
        brother[qq]++;
        record[i+1]=qq;



        dfs(i+1);







    }





}









int main()
{


    while (1)
    {
        memset(pre,0,sizeof(pre));
        memset(pos,0,sizeof(pos));
        memset(brother,0,sizeof(brother));
        memset(record,0,sizeof(0));

        m=0;
        level=0;
        result=1;


        cin >> ary;
        if (ary==0)
        {
            break;
        }

            cin >> pre >> pos;

            if (strlen(pre)==1)
            {
                result=1;
            }
            else
              dfs(0);
            cout << result << endl;

         
     


            

    }

 


    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator