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

我会再来的!

Posted by kuki at 2010-08-09 15:04:27 on Problem 2392
#include<stdio.h>
#include<stdlib.h>
#include<memory.h>
struct COW
{
	int h;
	int a;
	int c;
};
COW cow[405];
int dp[40005];
int max(int x,int y)
{
	return (x)>(y)?(x):(y);
}
int cmp(const void * p1,const void * p2)
{
	return ((COW *)p1)->a-((COW *)p2)->a;
}
int main()
{
//	freopen("in.txt","r",stdin);
	int i,j,k,N;
	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		scanf("%d%d%d",&cow[i].h,&cow[i].a,&cow[i].c);
	}
	qsort(cow,N,sizeof(cow[0]),cmp);
	memset(dp,0,sizeof(dp));
	//for(i=0;i<=cow[N-1].a;i++)
	//	printf("%d->%d\n",i+1,dp[i]);
	for(i=0;i<N;i++)
	{
		for(j=0;j<cow[i].c;j++)
		{
			for(k=cow[i].a;k>=cow[i].h;k--)
				dp[k]=max(dp[k],dp[k-cow[i].h]+cow[i].h);
		}
	
	}
//	for(i=0;i<=cow[N-1].a;i++)
	//	printf("%d->%d\n",i+1,dp[i]);
	printf("%d\n",dp[cow[N-1].a]);
	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