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 |
严重超时 xd帮偶看看啊 !!!#include "stdio.h" #include "String.h" #define max 200 int n,h; int fi[max],di[max],ti[max],fi2[max]; int lack[max],sum; int res[max],finshnum,res_end[max]; int enumeTi(int ,int ); int finshing(int,int); int main() { int i,j; while(scanf("%d",&n)&&n!=0){ scanf("%d",&h); h=h*60; for(i=1; i<=n; i++){ scanf("%d",&fi[i]); } for(i=1; i<=n; i++){ scanf("%d",&di[i]); } ti[0]=0; ti[1]=0; for(i=2; i<=n; i++){ scanf("%d",&ti[i]); ti[i]=ti[i]*5+ti[i-1]; } finshnum=0; sum=0; lack[0]=1; enumeTi(1,1) ; for(i=1; i<=n-1; i++){ printf("%d, ",res_end[i]); } printf("%d",res_end[i]); printf("\n"); printf("Number of fish expected: %d\n\n",finshnum); } return 0; } int enumeTi(int pos,int posL) { int i,temp; for(i=pos; i<=n; i++){ temp=ti[i]-ti[lack[posL-1]]; if(sum+temp>h) { break; } lack[posL]=i; sum+=temp; posL++; finshing(posL,sum); enumeTi(i+1,posL); posL--; sum-=temp; } return 0; } int finshing(int posL,int sum) { int i,m,mp,resSum=0; memset(res,0,sizeof(res)); for(i=1; i<posL; i++){ fi2[lack[i]]=fi[lack[i]]; } while(sum+5<=h){ m=0; mp=1; for(i=1; i<posL; i++){ if(m<fi2[lack[i]]) { m=fi2[lack[i]]; mp=lack[i]; } } resSum+=fi2[mp]; res[mp]+=5; if(fi2[mp]>di[mp]){ fi2[mp]-=di[mp]; } else { fi2[mp]=0; } sum+=5; } if(resSum>finshnum) { finshnum=resSum; for(i=1; i<=n; i++){ res_end[i]=res[i]; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator