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

求大神解释为何TLE..

Posted by QHearting at 2015-02-06 14:44:46 on Problem 1014
#include <stdio.h>
#include <time.h>

int value[7];

int dfs(int n);

int main(){
    int i,
    sum, nCase = 0;

    while(scanf("%d%d%d%d%d%d", &value[1], &value[2], &value[3], &value[4], &value[5], &value[6])){
        if(!value[1] && !value[2] && !value[3] && !value[4] && !value[5] && !value[6]) break;
        printf("Collection #%d:\n", ++nCase);
        for(i=1; i<=6; i++){
if(value[i]>60){
            if(value[i]%2) value[i] = 61;
            else value[i] = 60;
}
        }
        sum = value[1]*1 + value[2]*2 + value[3]*3 + value[4]*4 + value[5]*5 + value[6]*6;
        if(!(sum%2) && dfs(sum>>1)) printf("Can be divided.\n\n");
        else printf("Can't be divided.\n\n");
    }
    return 0;
}

int dfs(int n){
    int i;

    if(n<0) return 0;
    if(n==0){
        return 1;
    }
    for(i=6; i>0; i--){
        if(value[i]>0){
            value[i] --;
            if(dfs(n-i)) return 1;
            value[i] ++;
        }
    }

    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