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 |
严重超时!大虾在哪里?方法不对头? #include<iostream.h> int nt,n,r[24],t[1001]; int num,tt,max=99999; int fun(int,int); int main() { int i,s=0; cin>>nt; while(nt--) { num=0; for(i=0;i<24;i++) {scanf("%d",r+i);if(r[i]>0)s++;} cin>>n; for(i=0;i<n;i++) scanf("%d",t+i); tt=fun(0,s); if(tt==max)printf("No Solution\n"); else printf("%d\n",tt); } return 0; } int fun(int k,int s) { int c,x,y,i; if(s<=0)return 0; if(k>n-1) { if(!s)return 0; else return max; } if(s>=n-k)x=max; else x=fun(k+1,s); for(i=t[k];i<=t[k]+7;i++) { c=i%24; r[c]--; if(r[c]==0)s--; } y=fun(k+1,s)+1; for(i=t[k];i<=t[k]+7;i++) { c=i%24; r[c]++; if(r[c]==1)s++; } return x<y?x:y; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator