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

D_BUG最怕的就是这个,我下网上的AC程序,字制了很多组测试数据,但是就是找不到BUG,我只能说我是白痴,谁帮忙指一下BUG,让我死个明白

Posted by smallbox at 2008-09-11 15:59:37 on Problem 1699
#include "stdio.h"
#include "string.h"
int n;
int Pow[12];
int DP[2400][12];
char str[12][22];
int Ls[12][12];
int len[12];
void cal()
{
     for(int i=0;i<n;i++)
       for(int j=0;j<n;j++)
       {
           int max=0;
           for(int k=0;k<len[i];k++)
           {
                 bool equal=true;
                 for(int x=k,y=0;x<len[i]&&y<len[j];x++,y++)
                 if(str[i][x]!=str[j][y])
                 {
                     equal=false;break;
                 }
                 if(equal==true){max=len[i]-k; break;}
           }
           Ls[i][j]=max;         
       }
}
int Fun(int state,int last)
{
     int state_pre=state;    
     state_pre=state_pre&(~(1<<last)); 
    int s;
    if(state_pre==0)return len[last];
    if(DP[state][last]!=0)return DP[state][last];
    int min=9999999;
    for(int i=0;i<n;i++)
    {
         int t=state_pre&(~(1<<i));
         if(t!=state_pre)
         {
              int length=Fun(state_pre,i)+len[last]-Ls[i][last]; 
              min<?=length;                      
         }        
    }
    DP[state][last]=min;
    return min;
}
main()
{
    int T;
    Pow[0]=1;
    for(int i=1;i<11;i++)
      Pow[i]=Pow[i-1]*2;
    scanf("%d",&T);
    while(T--)
    {
        memset(DP,0,sizeof(DP));
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
          scanf("%s",str[i]);        
          len[i]=strlen(str[i]);
        }
        cal();
       int min=9999999;
       for(int i=0;i<n;i++)
       {
            int length=Fun(Pow[n]-1,i);
            min<?=length;
       }
       printf("%d\n",min); 
    }      
}

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