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

自我感觉良好 125秒

Posted by 542935296 at 2011-04-19 14:37:46 on Problem 2392
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define maxn 400002
struct PP
{
	int c,acc,below;
} q[420];
bool cmp(PP a,PP b)
{
	return a.below<=b.below;
}
int f[maxn];
int max(int a,int b) {return a>b? a:b;}
void zop(int c,int w,int v)
{
	int i;
	for(i=v;i>=c;i--)
		f[i]=max(f[i],f[i-c]+w);
}
void cp(int c,int w,int v)
{
	int i;
	for(i=c;i<=v;i++)
		f[i]=max(f[i-c]+w,f[i]);
}
void mp(int c,int w,int acc,int v)
{
	int k;
	if(acc*w>=v)
		cp(c,w,v);
	else
	{
		k=1;
		while(k<acc)
		{
			zop(k*c,k*w,v);
			acc-=k;
			k=k*2;
		}
		zop(acc*c,acc*w,v);
	}
}
int main()
{
	int n,c,acc,i,v,ans,j;
	while(scanf("%d",&n)!=EOF)
	{
		memset(f,0,sizeof(f));
		ans=acc=c=v=0;
		for(i=1;i<=n;i++)
		{
			scanf("%d%d%d",&q[i].c,&q[i].below,&q[i].acc);
			if(q[i].below>v) v=q[i].below;
			if(q[i].c>c) c=q[i].c;
			if(q[i].acc>acc) acc=q[i].acc;
		}
		if(v==0||c==0||acc==0) { printf("0\n"); continue; }
		sort(q+1,q+n+1,cmp);
		for(i=1;i<=n;i++)
			mp(q[i].c,q[i].c,q[i].acc,q[i].below);
		for(i=1;i<=v;i++)
		   if(f[i]>ans) { ans=f[i]; j=i;}
        printf("%d\n",ans);
	}
	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