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 antry at 2011-03-20 19:25:44 on Problem 1564
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int d[13],n,t,a[13],flag,ck[1000];
void antry(int v,int sum,int j)
{
    int i;
    if(sum>t) return;
    if(v>n) return;
    if(sum==t){
        int tmp[1000];
        memset(tmp,0,sizeof(tmp));
        for(i=0;i<j;i++)
            tmp[a[i]]++;
        for(i=0;i<j;i++)
            if(ck[a[i]]!=tmp[a[i]])
                    break;
        if(i==j) return;
        for(i=0;i<j;i++)
           ck[a[i]]=tmp[a[i]];
        flag=1;
        printf("%d",a[0]);
        for(i=1;i<j;i++)
            printf("+%d",a[i]);
        printf("\n");
        return;
    }
    for(i=v;i<n;i++){
        a[j]=d[i];
        antry(i+1,sum+a[j],j+1);
    }
}
int main()
{
    int i,j;
    while(scanf("%d%d",&t,&n)!=EOF){
        if(n==0) break;
        for(i=0;i<n;i++)
            scanf("%d",&d[i]);
        flag=0;
        memset(ck,0,sizeof(ck));
        printf("Sums of %d:\n",t);
        antry(0,0,0);
        if(!flag) printf("NONE\n");
    }
    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