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:为什么着题总超时啊,用的是宽搜,大牛门用的是什么算法,还是有好的减枝?In Reply To:为什么着题总超时啊,用的是宽搜,大牛门用的是什么算法,还是有好的减枝? Posted by:fjnu_jxd_010 at 2005-10-06 16:09:31 我的code #include<iostream> //#include<memory.h> using namespace std; /*int as(int t,int i,int sum,int head,int tail) { if(head>tail) return 0; t=s[head]; int j; if(sum>m)return 0; if(i==n+1) { if(sum<=m&&b[sum]==0) {max++;b[sum]=1;} return 0; } t++; for(j=0;j<=num[i];j++) as(t,i+1,sum+j*a[i]); // i++; return 0; } */ typedef struct node { int we; int sn[103]; }node ; node s[10005]; int main() { int a[2003],ma,n,m,j,ta,b[150008],num[2003],cw; int i,head,tail; while(scanf("%d%d",&n,&m)==2&&(n||m)) { head=0;tail=0;ta=0; ma=0; memset(b,0,sizeof(int)*(m+2)); memset(s,0,sizeof(s)); for(i=1;i<=n;i++) scanf("%d",&a[i]); for(i=1;i<=n;i++) scanf("%d",&num[i]); while(head+ta*10000<=tail+ma*10000) { for(i=1;i<=n;i++) if(s[head].sn[i]<num[i]) { cw=s[head].we+a[i]; if(cw<=m) if(!b[cw]) { tail++; if(tail==10001) { tail=1;ma++;} s[tail].we=cw;b[cw]=1; for(j=1;j<=n;j++) s[tail].sn[j]=s[head].sn[j]; s[tail].sn[i]++; } } head++; if(head==10001) {head=1;ta++;} } //as(1,0,head,tail); printf("%d\n",tail+30000*ma); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator