Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:请问有人能够将64的那组BT数据控制在1S之内么?In Reply To:Re:请问有人能够将64的那组BT数据控制在1S之内么? Posted by:chinaeli at 2009-04-05 19:20:36 #include <stdio.h> #include <stdlib.h> void find(int now, int left, int have, int total); int cmp(const void *p1, const void *p2); int N,min; int stick[100]; int visited[100] = {0}; int lost[110] = {0}; int flag = 0; int main() { int i, totallen; while(1){ scanf("%d", &N); if(!N) break; min = 0; totallen = 0; for(i=0; i<N; i++){ scanf("%d", &stick[i]); if(min < stick[i]) min = stick[i]; totallen += stick[i]; } qsort(stick, N, sizeof(stick[0]), cmp); while(min <= totallen){ if(totallen % min == 0){ for(i=0; i<N;i++) visited[i] = 0; flag = 0; find(N-1,0,0, N); if(flag){ printf("%d\n", min); break; } } min++; } } return 0; } void find(int now, int left, int have, int total){ int i; int j,right; if(flag) return; if(left == 0){ if(have==total) flag = 1; else{ for(i=0; i<=100; i++) lost[i] = 0; for(i=total-1; visited[i]; i--) ; visited[i] = 1; find(i-1,min-stick[i],have+1,total); } } else{ for(i=now; i>=0; i--){ if(stick[i]<=left && !visited[i]){ for(j=right=0; j<i; j++) if(!visited[j] && lost[stick[i]+stick[j]]){ right = 1; break; } if(!right){ visited[i] = 1; find(i-1,left-stick[i],have+1,total); visited[i] = 0; lost[stick[i]+stick[j]]++; } } } } } int cmp(const void *p1, const void *p2){ return (*(int*)p1 - *(int*)p2); } 1 秒内搞定 还是WA!!1 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator