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

真不知道自己怎么RTE的,哪位牛人帮忙啊,帮忙出出招

Posted by Essence_me at 2005-08-17 17:44:43 on Problem 2397
#include <stdio.h>
#include <string.h>
int high[2][501];
int step[1001];
char ways[2][501][1001];
int main()
{
	int n,m,i,j,k,p1,p2;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&m);
		for(j=0;j<m;j++)
		{
			scanf("%d",&step[j]);
		}
		for(j=0;j<2;j++)
			for(k=0;k<=500;k++)
			{
				high[j][k]=-1;
				ways[j][k][0]='\0';
			}
		high[0][0]=0;
		for(j=0;j<m;j++)
		{
			if(j%2==0)
			{
				p1=0;
				p2=1;
			}
			else
			{
				p1=1;
				p2=0;
			}
			for(k=0;k<=500;k++)
			{
				int h1,len;
				if(high[p1][k]==-1)continue;
				if(step[j]+k>=0&&step[j]+k<=500)
				{
					if(k+step[j]>high[p1][k])h1=k+step[j];
					else h1=high[p1][k];
					if(high[p2][k+step[j]]==-1||h1<high[p2][k+step[j]])
					{
						high[p2][k+step[j]]=h1;
						strcpy(ways[p2][k+step[j]],ways[p1][k]);
						len=strlen(ways[p2][k+step[j]]);
						ways[p2][k+step[j]][len]='U';
						ways[p2][k+step[j]][len+1]='\0';
					}
				}
				if(k-step[j]>=0&&k-step[j]<=500)
				{
					if(k-step[j]>high[p1][k])h1=k-step[j];
					else h1=high[p1][k];
					if(high[p2][k-step[j]]==-1||h1<high[p2][k-step[j]])
					{
						high[p2][k-step[j]]=h1;
						strcpy(ways[p2][k-step[j]],ways[p1][k]);
						len=strlen(ways[p2][k-step[j]]);
						ways[p2][k-step[j]][len]='D';
						ways[p2][k-step[k]][len+1]='\0';
					}
				}
			}
			for(k=0;k<=500;k++)
			{
				high[p1][k]=-1;
			}
		}
		
		if(high[p2][0]==-1)printf("IMPOSSIBLE\n");
		else printf("%s\n",ways[p2][0]);
	}
	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