Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
D_BUG最怕的就是这个,我下网上的AC程序,字制了很多组测试数据,但是就是找不到BUG,我只能说我是白痴,谁帮忙指一下BUG,让我死个明白#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator