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

找了个标称 随即做的所有数据全部和我的一样 可是我还是WA 求助

Posted by zaiyebuwr at 2009-08-04 14:22:52 on Problem 2817
#include<iostream>
#include<cstring>
using namespace std;
int i,j,k,n,m,q,r[1000],f[11][300][300],a[11][11],d[11][300];
char s[11][101];
int main()
{
    r[1]=1;r[2]=2;r[4]=3;r[8]=4;r[16]=5;r[32]=6;
    r[64]=7;r[128]=8;r[256]=9;r[512]=10;
    while(scanf("%d",&n),n>0)
    {
        memset(d,0,sizeof(d)); 
        for (i=1;i<=(1<<n)-1;i++)
        {
            j=i;
            m=0;
            while (j!=0)
            {
                j-=j&(-j);
                m++;
            }
            d[m][0]++;
            d[m][d[m][0]]=i;
        }
        getchar();
        for (i=1;i<=n;i++) 
        scanf("%s",s[i]);
        memset(a,0,sizeof(a));
        for (i=1;i<=n;i++)
        for (j=1;j<=n;j++)
        if (i!=j)
            for (k=0;k<strlen(s[i]);k++)
            {
                m=0;
                for (q=0;q<(strlen(s[j]),strlen(s[i])-k);q++)
                if (s[i][k+q]==s[j][q])
                m++;
                a[i][j]=max(m,a[i][j]);
            }

        for (i=1;i<=n;i++)
        for (j=1;j<=n;j++)
        a[i][j]=max(a[i][j],a[j][i]);
        memset(f,0,sizeof(f));
        for (i=2;i<=n;i++)
        {
             for (j=1;j<=d[i][0];j++) 
             for (k=1;k<=d[i-1][0];k++)
             if ((d[i][j]|d[i-1][k])==d[i][j])
             {
                    if (i==2)
                    f[i][j][k]=a[r[d[i][j]^d[i-1][k]]][r[d[i-1][k]]];
                    for (q=1;q<=d[i-2][0];q++)
                    if ((d[i-1][k]|d[i-2][q])==d[i-1][k])
                     f[i][j][k]=max(f[i][j][k],f[i-1][k][q]+a[r[d[i][j]^d[i-1][k]]][r[d[i-1][k]^d[i-2][q]]]);
               
            }
        }
        m=0;
        for (i=1;i<=d[n-1][0];i++)
        if (f[n][1][i]>m)
        m=f[n][1][i];
        printf("%d\n",m);
        
    }
    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