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

为什么总是WA呀? 都是按照解题报告上的方法来的,大侠帮忙看下错哪了,谢谢!!!

Posted by 20050503 at 2007-06-07 10:39:11 on Problem 1160
#include<iostream>
#include<vector>
using namespace std;

#define max 10000000

int main()
{
	int n;//the number of the villege
	int m;//the number of the postoffice
	while(cin>>n>>m)
	{
	if(m==n)
	{
		cout<<'0'<<endl;
		continue;
	}
	int vpos[302];
	int  i, j;
	for(i=0; i<n; i++)
		cin>>vpos[i+1];
	int dis[302][32]={0};
	int cost[302][32]={0};
	for(i=1; i<=n; i++)//the smallest distance between posi ans posj if there just one post office
		for(j=1; j<=n; j++)
			if(i>=j)
				dis[i][j] =0;
			else
				dis[i][j] = dis[i][j-1]+vpos[j]-vpos[(i+j)/2];

	for(i=1; i<=n; i++)
		cost[i][1] = dis[1][i];
	for(i=2; i<=m; i++)
		for(j=i+1; j<=n;  j++)
		{
			int mid;
			cost[j][i] = max;
			for(int t=i-1; t<=j; t++)
			{
				mid = cost[t][i-1] + dis[t+1][j];//cost[n,m]=cost[r,m-1]+dis[r+1,n]
				if(mid<cost[j][i])
					cost[j][i] = mid;//take the smallest distance
			}
		}
	cout<<cost[n][m]<<endl;
	}
	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