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 y05dzz at 2007-09-17 21:07:23 on Problem 2353
#include<iomanip.h>
#include<stdio.h>
struct node
{
	int v;
	char ch;
}map[200][900];
int value[200][900];
int temp[9000];
int min=1000000000;
int main()
{
	int m,n,i,j,k,tmp,k1,k2,k3;
	scanf("%d%d",&m,&n);
	for(i=1;i<=m;i++)
	{
		for(j=1;j<=n;j++)
		{
			scanf("%d",&value[i][j]);
		}
	}
	for(i=1;i<=n;i++)
	{
		map[1][i].v=value[1][i];
		map[1][i].ch='n';map[m][i].ch='u';
	}
	for(i=2;i<m;i++)
	{
		for(j=1;j<=n;j++)
		{
			min=1000000000;
			tmp=0;
			for(k=1;k<j;k++)
			{
				tmp+=map[i-1][k].v;
				for(k1=k;k1<j;k1++)
				{
					tmp+=value[i][k1];
				}
				if(tmp<min)
				{
					k3=k;
					min=tmp;
				}
				tmp=0;
			}
			for(k=n;k>j;k--)
			{
				tmp+=map[i-1][k].v;
				for(k2=k;k2>j;k2--)
				{
					tmp+=value[i][k2];
				}
				if(tmp<min)
				{
					k3=k;
					min=tmp;
				}
				tmp=0;
			}
			tmp=map[i-1][j].v;
			if(tmp<=min)
			{
				k3=j;
				min=tmp;
			}
			map[i][j].v=min+value[i][j];
			if(k3<j)map[i][j].ch='l';
			if(k3==j)map[i][j].ch='u';
			if(k3>j)
			{
			//	map[i][j].ch='r';
				map[i][j++].ch='r';
				for(;j<k3;j++)
				{
					map[i][j].ch='r';
					map[i][j].v=min;
					min=min-value[i][j];
				}
				map[i][j].ch='u';
				map[i][j].v=min;
			}
			min=1000000000;
		}
	}
	for(i=1;i<=n;i++)
	{
		if(map[m][i].v<min)
		{
			min=map[3][i].v;
			k=i;
		}
	}
	i=m;j=k;k3=0;
	while(map[i][j].ch!='n')
	{
		temp[k3++]=j;
		if(map[i][j].ch=='u')i--;else
		if(map[i][j].ch=='l')j--;else
		if(map[i][j].ch=='r')j++;
	}
	printf("%d\n",j);
	for(i=k3-1;i>=0;i--)
	{
		printf("%d\n",temp[i]);
	}
	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