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

我的程序,2187MS...汗~~~希望能有牛人贴个好的上来

Posted by Spacesheep at 2005-08-29 23:11:42
In Reply To:http://acm.pku.edu.cn/JudgeOnline/showproblem?problem_id=1742 跪求AC了的Code,我TLE了一晚上了。。。 Posted by:xxxlxr at 2005-08-29 16:07:24
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

struct point{
	int a,c;
}p[101];

int i,j,r,n,m,nowmax,dome,ans,t,tt;
int pp[100001];
bool q[100001];

bool comp(point &a,point &b){
	return a.a>b.a;
};

void make(){
	for (i=1;i<=n;i++){
		tt=t;
		for (j=1;j<=tt;j++){
				dome=pp[j];
				r=p[i].c;
				while (r&&dome+p[i].a<=m&&!q[dome+p[i].a]){
					r--;
					dome+=p[i].a;
					q[dome]=1;
					t++;pp[t]=dome;
				};
			
		};
		if (t>m) break;
	};
	printf("%d\n",t-1);
	return;
};

void main(){
	p[0].a=9999999;
	while (scanf("%d %d",&n,&m),n){
		for (i=1;i<=n;i++) scanf("%d",&p[i].a);
		for (i=1;i<=n;i++) scanf("%d",&p[i].c);
		sort(p,p+n+1,comp);
		memset(q,0,sizeof(q));
		q[0]=1;
		t=1;
		pp[1]=0;
		ans=0;nowmax=0;
		make();

	};
	return; 
};


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