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 lzxzy at 2018-08-24 16:06:10 on Problem 3984
In Reply To:水题,用BFS存上父节点,倒序输出就可以了。 Posted by:1196494730 at 2018-08-24 11:27:15
#include <cstdio>
#include <cstring>
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
int a[10][10],f[10][10];

void into()
{
	for(int i=0;i<5;i++)
		for(int j=0;j<5;j++)
			scanf("%d",&a[i][j]);
}

void js()
{
	memset(f,0x3f,sizeof(f));
	f[0][0]=0;
	for(int i=0;i<5;i++)
		for(int j=0;j<5;j++)
			if(!a[i][j])
			{
				if(i-1>=0)f[i][j]=Min(f[i][j],f[i-1][j]);
				if(j-1>=0)f[i][j]=Min(f[i][j],f[i][j-1]);
				f[i][j]++;
			}
}

void train(int x,int y)
{
	if(x==0 && y==0)
	{
		printf("(%d, %d)\n",x,y);
		return ;
	}
	if(f[x-1][y]<f[x][y-1])train(x-1,y);
	else train(x,y-1);
	printf("(%d, %d)\n",x,y);
}

int main()
{
	into();
	js();
	train(4,4);
	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