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

问题出在sort,注意你的数据的下标是从1开始的//Re:一直WA 求大神相救 贴上代码 和 思路

Posted by yangzhenjian at 2016-07-15 22:03:54 on Problem 1036
In Reply To:一直WA 求大神相救 贴上代码 和 思路 Posted by:xwd358527617 at 2011-09-24 20:18:37
> #include <iostream>
> #include <cstdio>
> #include <algorithm>
> using namespace std;
> 
> int N,T,K;
> int v[101][101];
> int dp[101][101];
> 
> struct info
> {
> 	int t,s,p;
> };
> 
> info rec[101];
> 
> bool cmp(info a,info b)
> {
> 	return a.t <= b.t;
> }
> 
> 
> int main()
> {
> 	scanf("%d%d%d",&N,&K,&T);
> 	for(int i=1;i<=N;i++)
> 		scanf("%d",&rec[i].t);
> 	for(int i=1;i<=N;i++)
> 		scanf("%d",&rec[i].p);
> 	for(int i=1;i<=N;i++)
> 		scanf("%d",&rec[i].s);
>         // 输入 数据
> 	sort(rec,rec + N,cmp);
>         // 按时间戳排序
> 	for(int i=1;i<=N;i++)
> 		v[i][rec[i].s] += rec[i].p;
> 
>         //将数据存入v[i][j] ,表示 第i个时间戳 门的state为j时候的propersity
> 	dp[0][0] = 1;
>         // dp表示 第i个时间戳 门的state为j时候的最大propersity.
>         //dp[0][0] = 1 开始时候 dp = 1是为了后面可以以此判断下个时间戳是否                          //可以走到
> 	for(int i=1;i<=N;i++)
> 	{
> 		for(int j=0;j<=K;j++)
> 		{
> 			int di = rec[i].t - rec[i-1].t;
> //时间差..
> 			int maxn = 0;
> 			for(int k = (j-di>0?j-di:0) ;k<=(j+di<K?j+di:K);k++)
> 				if(maxn < dp[i-1][k])
> 					maxn = dp[i-1][k];
> 			if(maxn)
> 				dp[i][j] += v[i][j];
> 			dp[i][j] += maxn;		
> 		}
> 	}
> 
> 	int maxn = 0;
> 	for(int i=0;i<=K;i++)
> 		if(maxn < dp[N][i])				
> 			maxn = dp[N][i];
> 
> 	if(maxn == 0)
> 		printf("0");
> 	else
> 		printf("%d\n",maxn - 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