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

哭啊,为什么我的也是O(nm)的,但是就超时呢?

Posted by hanjialong at 2008-09-03 18:41:25 on Problem 1742
555555555555

#include<iostream>
using namespace std;

const int maxm=100100,maxc=101;

struct value
{
	bool ok;
	short int coin[maxc];
};

struct coi
{
	int a;
	short int c;
};

coi c[maxc];

int cmp(const void *a,const void *b)
{
	return ((coi*)a)->a-((coi*)b)->a;
}

value v[maxm];

int a[maxm];

int main()
{
	int i,j,n,m,maxim,t;
	while(scanf("%d%d",&n,&m)&&(n||m))
	{
		for(i=0;i<m;i++)
			v[i].ok=0;
		for(i=0;i<n;i++)
		scanf("%d",&c[i].a);
		for(i=0;i<n;i++)
			scanf("%d",&c[i].c);
		qsort(c,n,sizeof(coi),cmp);
		memset(v[0].coin,0,sizeof(v[0].coin));
		v[0].ok=1;maxim=0;
		for(i=0;i<=maxim;i++)
			if(v[i].ok)
			{
				for(j=0;j<n;j++)
				{
					t=i+c[j].a;
					if(t>m) break;
					if(v[i].coin[j]<c[j].c&&!v[t].ok)
					{
						if(t>maxim) maxim=t;
						v[t]=v[i];
						v[t].coin[j]++;
					}
				}
			}
		int s=0;
		for(i=1;i<=m;i++)
			if(v[i].ok) s++;
		printf("%d\n",s);
	}
	return 0;
}

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