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 liulibo133 at 2007-06-01 02:45:10 on Problem 1821
In Reply To:喜欢动态规划的进来!!! Posted by:tempfor at 2007-05-31 21:12:59
> 
> 程序哪里错了!!!
> #include<iostream>
> #include<algorithm>
> using namespace std;
> int f[32000],N,K;
> struct node
> {
> 	int L,P,S;
> }W[128];
> int cmp(node a,node b)
> {
> 	return a.S<b.S;
> }
> inline int big(int a,int b)
> {
> 	return a>b?a:b;
> }
> void DP()
> {
> 	int i,j,t,s;
> 	sort(W,W+K,cmp);
> 	memset(f,0,sizeof(f));
> 	int g,p;
> 	for(i=0;i<K;i++)
> 	{
> 		g=f[W[i].S];
> 		p=W[i].P*W[i].L;
> 		int mm=f[W[i].S],id=0;
> 		t=W[i].S-1;
> 		for(j=W[i].S+W[i].L-1;j>=W[i].S;j--,t--)
> 		{
> 			if(t<0)
> 			{
> 				if(f[j]<W[i].P*j)
> 				{
> 					f[j]=W[i].P*j;
> 				}
> 				continue;
> 			}
> 			else
> 			{
> 				g=big(g-W[i].P,f[t]);
> 			}
> 			if(g+p>f[j])
> 			{
> 				f[j]=g+p;
> 				if(f[j]>mm)
> 				{
> 				    mm=f[j];
> 				    id=j;
> 				}
> 			}
> 
> 		}
> 	    s=W[i].S+W[i].L-1;;
> 		if(id==0)
> 		{
> 			continue;
> 		}
> 		for(j=s+1;j<=N;j++)
> 		{
> 			f[j]=f[s];
> 		}
> 	}
> 	printf("%d\n",f[N]);
> }
> int main()
> {
> 	while(scanf("%d%d",&N,&K)!=EOF)
> 	{
> 		int i;
> 		for(i=0;i<K;i++)
> 		{
> 			scanf("%d%d%d",&W[i].L,&W[i].P,&W[i].S);
> 		}
> 		DP();
> 	}
> 	return 1;
> }
> 
> 
> 
> 
> 

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