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

这程序为什么runtime error啊,菜鸟求解释

Posted by Kuaitoukid at 2013-07-13 22:08:37 on Problem 1015
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;
int dp[21][801];
int path[21][801];
bool select(int i, int j, int k, int* v)
{
	for (int n = 1; n <= j; n ++){
		if (i == path[n][k])
			return true;
		k -= v[path[n][k]];
	}
	return false;
}
int main()
{
	int n, m;
	int round = 1;
	int p[300], d[300], s[300], v[300];
	while(true)
	{
		scanf("%d %d", &n, &m);
		if (n == 0 && m == 0)
			break;

		memset(dp, -1, sizeof(dp));
		memset(path, 0, sizeof(path));
		for (int i = 1; i <= n; i ++)
		{
			scanf("%d %d", &p[i], &d[i]);
			s[i] = p[i] + d[i];
			v[i] = p[i] - d[i];
		}
		int fix = 20 * m;
		dp[0][fix] = 0;
		for (int j = 1; j <= m; j ++){
			for (int k = 0; k <= 2 * fix; k ++){
				if (dp[j-1][k] >= 0){
					for (int i = 1; i <= n; i ++){
						if (dp[j][k + v[i]] < dp[j-1][k] + s[i]){
							if (!select(i, j, k, v)){
								dp[j][k+v[i]] = dp[j-1][k] + s[i];
								path[j][k+v[i]] = i;
							}
						}
					}
				}
			}
		}
		int k;
		for (k = 0; k <= fix; k ++)
			if (dp[m][fix + k] >= 0 || dp[m][fix - k] >= 0)
				break;

		int re1 = (dp[m][k + fix] > dp[m][fix - k]) ? dp[m][k + fix] : dp[m][fix - k];
		int re2 = (dp[m][k + fix] > dp[m][fix - k]) ? k : -k;

		printf("Jury #%d\n", round ++);
		printf("Best jury has value %d for prosecution and value %d for defence:\n", (re1 + re2)>>1, (re1 - re2)>>1);

		int id[300];
		int j = m;
		k = (dp[m][k + fix] > dp[m][fix - k]) ? k + fix : fix - k;
		for (int i = 0; i < m; i ++){
			id[i] = path[j--][k];
			k -= v[id[i]];
		}
		sort(id, id + m);
		for (int i = 0; i < m; i ++)
			printf(" %d", id[i]);
		printf("\n\n");
	}
	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