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 ice5713 at 2009-10-01 22:19:46
各路牛人,谁能告诉我我的代码是怎么回事,老是Runtime Erorr,我修改好了多次,始终发现不了问题出在哪,题目是1036,Gangsters,代码如下:

#include <iostream>
#include <cmath>
#include <stdio.h>

using namespace std;

int t[101], p[101], s[101], a[101][101];
int N, K, T;

bool isValid(int time, int x) {
	if (time >= 0 && time <= T && x >= 0 && x <= K)
		return true;
	return false;
}

int localOptimize(int time, int x) {
	int max = -100;
	if (isValid(time - 1, x - 1)) {
		if (a[time - 1][x - 1] > max)
			max = a[time - 1][x - 1];
	}
	if (isValid(time - 1, x)) {
		if (a[time - 1][x] > max)
			max = a[time - 1][x];
	}
	if (isValid(time - 1, x + 1)) {
		if (a[time - 1][x + 1] > max)
			max = a[time - 1][x + 1];
	}
	for (int i = 0; i < N; i++) {
		if (time == t[i] && x == s[i])
			max += p[i];
	}
	return max;
}

int main() {
	int intMin = -100;

	scanf("%d %d %d",&N, &K, &T);

	int i = 0;
	for (i = 0; i < N; i++)
		scanf("%d",&t[i]);
	for (i = 0; i < N; i++)
		scanf("%d",&p[i]);
	for (i = 0; i < N; i++)
		scanf("%d",&s[i]);

	// time == 0, initial state
	a[0][0] = 0;
	for (int i = 1; i < K + 1; i++)
		a[0][i] = intMin;

	// find the optimized solution
	for (int time = 1; time <= T; time++) {
		for (int x = 0; x <= K; x++) {
			a[time][x] = localOptimize(time, x);
		}
	}

	int best = 0;
	for(int i = 0; i <= K; i++ ) {
		if( a[T][i] > best )
			best = a[T][i];
	}

	printf("%d\n",best);
}

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