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 XiaXu at 2005-07-16 05:14:08 on Problem 1062
#include<iostream>
#include<math.h>
using namespace std;

class Node
{
public:
	long int value,grade,indegree;
	long int preNode[100][2];
};

long int result(long int G[101][101],int n)
{
	int i,j;
	long int min,D[101];
	for(j=1;j<=n;j++)
		D[j]=G[0][j];
	for(j=1;j<=n;j++)
	{
		min=D[j];
		for(i=1;i<j;i++)
		{
			if(G[i][j]<=min)
			{if(G[i][j]!=-1) min=G[i][j];}
			else continue;
		}
		for(i=0;i<=n;i++)
			if(G[j][i]!=-1) G[j][i]+=min;
	}
	min=G[0][n];
	for(i=0;i<n;i++)
	{if(G[i][n]!=-1&&G[i][n]<min) min=G[i][n];}
	return min;
}

int main()
{
	int m,n;
	int i,j,k;
	cin>>m>>n;
	if(n==0) printf("%d\n",0);
	else{
	Node node[101];
	for(i=1;i<=n;i++)
	{
		cin>>node[i].value>>node[i].grade>>node[i].indegree;
		for(j=0;j<node[i].indegree;j++)
			cin>>node[i].preNode[j][0]>>node[i].preNode[j][1];
	}


	long int array[101][101];
	for(i=0;i<=n;i++)
		for(j=0;j<=n;j++)
			array[i][j]=-1;

    for(i=1;i<=n;i++)
		array[0][i]=node[i].value;
	for(i=1;i<n;i++)
		for(j=i+1;j<=n;j++)
		{
			for(k=0;k<node[i].indegree;k++)
			if(node[i].preNode[k][0]==j&&node[i].grade-node[j].grade<=m)
				array[i][j]=node[i].preNode[k][1];
		}
    
	long int temp;
    for(j=1,k=n;j<k;j++,k--) {temp=array[0][j];array[0][j]=array[0][k];array[0][k]=temp;}
    for(i=1;i<=n;i++)
		for(j=1;j<=n-i+1;j++)
		{temp=array[i][j];array[i][j]=array[n+1-j][n+1-i];array[n+1-j][n+1-i]=temp;}

	long int res;
	res=result(array,n);
	printf("%ld\n",res);
	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