PersonalCorpus 版 (精华区)

1122031 2002/09/27 08:09:25.309 Accepted
0:00.150 392 18188 C++ 10364 - Square


    int n,t,aver;
    int a[20];
    bool used[20],ok;

int readnum()
{
    char ch;
    int i=0;

    do {
        scanf("%c",&ch);
    } while (!isdigit(ch));

    do {
        i*=10;
        i+=ch-48;
        scanf("%c",&ch);
    } while (isdigit(ch));
    return i;
}

void tryit (int level, int num, int left)
{
    int i,j,k;

    if (ok) return;

    if (left==0) {
        if (level==2) ok=true; else tryit(level+1,0,aver);
        return;
    }
    k=-1;
    for (i=num;i<n;i++) if (!used[i]) if (a[i]<=left) if (a[i]!=k) {
        used[i]=true;
        k=a[i];
        tryit(level,i+1,left-a[i]);
        used[i]=false;
    }
}


void main()
{
#ifndef ONLINE_JUDGE
    freopen("c:\\0acm\\uva\\contest9-21\\iC","r",stdin);
    freopen("c:\\0acm\\uva\\contest9-21\\oC","w",stdout);
#endif

    int i,j,k;

    t=readnum();
    while (t>0) {
        t--;
        n=readnum();
        for (i=0;i<n;i++) a[i]=readnum();

        for (i=0;i<n-1;i++) for (j=i+1;j<n;j++) if (a[i]<a[j]) {
            k=a[i]; a[i]=a[j];a[j]=k;
        }
        aver=0;
        for (i=0;i<n;i++) aver+=a[i];
        if ((aver%4)!=0) {
            printf("no\n");
            continue;
        }
        aver/=4;
        if (a[0]>aver) {
            printf("no\n");
            continue;
        }
        memset(used,0,sizeof(used));
        ok=false;
        tryit(0,0,aver);
        if (!ok) printf("no\n"); else printf("yes\n");


    }


}
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.096毫秒