PersonalCorpus 版 (精华区)

1240983 Big Guava ... 167 Accepted
0:00.002 64 2002/11/16 05:24:39.943

int n=0;
char c[92][8],path[8];
char m[8][8];
bool col[8],d[15],dd[15];

void tryit (int dep)
{
    if (dep==8) {
        memcpy(c[n],path,sizeof(path));
        n++;
        return;
    }
    int i;
    for (i=0;i<8;i++) if (!col[i]&&!d[dep-i+7]&&!dd[dep+i]) {
        path[dep]=i;
        col[i]=d[dep-i+7]=dd[dep+i]=true;
        tryit(dep+1);
        col[i]=d[dep-i+7]=dd[dep+i]=false;
    }
}


void main()
{
#ifndef ONLINE_JUDGE
    freopen("k:\\uva\\i167","r",stdin);
    freopen("k:\\uva\\o167","w",stdout);
#endif

    int i,j,k,l,t;

    memset(m,0,sizeof(m));
    memset(col,0,sizeof(col));
    memset(d,0,sizeof(d));
    memset(dd,0,sizeof(dd));

    tryit(0);

    scanf("%d\n",&k);
    while (k--) {
        for (i=0;i<8;i++) for (j=0;j<8;j++) scanf("%d",&m[i][j]);
        n=0;
        for (i=0;i<92;i++) {
            l=0; for (j=0;j<8;j++) l+=m[j][c[i][j]];
            if (l>n) n=l;
        }
        printf("%5d\n",n);
    }
}
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.020毫秒