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 1192931533 at 2016-07-29 09:34:00 on Problem 2907
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;
int o,n,m,X,Y,k,a[30][30],ans=10000000,num,A,B;

void dfs(int x,int y,int q)
{
	//if(num>=ans) return;
	if(q==0)
	{
		num+=abs(x-X)+abs(y-Y);
		cout<<num<<endl;
		if(ans>num)  ans=num;
	}
	a[x][y]=0;
	for(int i=0;i<=n;i++)
	    for(int j=0;j<=m;j++)
	        if(a[i][j])
	        {
	        	a[i][j]=0;
	        	num+=abs(i-x)+abs(j-y);
	        	dfs(i,j,q-1);
	        	num-=abs(i-x)+abs(j-y);
				a[i][j]=1;
			}
}

int main()
{
	//freopen("sss.in","r",stdin);
    //freopen("sss.out","w",stdout);
	cin>>o;
	while(o)
	{
		for(int i=0;i<=25;i++)
		    for(int j=0;j<=25;j++)
		        a[i][j]=0;
		num=0;ans=10000000;
		cin>>n>>m>>X>>Y>>k;
		for(int i=1;i<=k;i++)  scanf("%d%d",&A,&B),a[A][B]=1;
		dfs(X,Y,k);
		printf("The shortest path has length %d\n",ans);
		o--;
	}
	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