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

求助!!!!一样的代码却总是RE????抓狂了!!!

Posted by 20114434 at 2012-08-10 20:27:19 on Problem 1160
这是我的Java代码:(RE无数次!!!)
import java.util.Scanner;

public class Main{
	static int[] pos = new int[310];
	static int[][] sum = new int[310][310];
	static int[][] dp = new int[310][31];
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int V = cin.nextInt();
		int P = cin.nextInt();
		for (int i = 1; i <= V; i++) {
			pos[i] = cin.nextInt();
		}
		for (int i = 1; i < V; i++) {
			for (int j = i + 1; j <= V; j++) {
				sum[i][j] = sum[i][j - 1] + pos[j] - pos[(i + j) / 2];
			}
		}
		for (int i = 1; i <= V; ++i) {
			dp[i][i] = 0;
			dp[i][1] = sum[1][i];
		}
		for (int j = 2; j <= P; ++j) {
			for (int i = j + 1; i <= V; ++i) {
				dp[i][j] = 9999999;
				for (int k = j - 1; k < i; ++k)
					dp[i][j] = Math.min(dp[i][j], dp[k][j - 1] + sum[k + 1][i]);
			}
		}
		System.out.printf("%d\n", dp[V][P]);
	}
}
这是已经AC了的C++代码,有什么区别吗?

#include <cstdio>
#include <cstring>
using namespace std;
#define min(a,b) (a) < (b) ? (a) : (b)
int dp[310][31];
int sum[310][310];
int V,P;
int pos[310];
int main(){
		scanf("%d%d",&V,&P);
        for(int i = 1; i <= V; ++i)scanf("%d",&pos[i]);
        for(int i=1 ; i< V ; i++){
        for(int j=i+1 ; j<= V ; j++){
            sum[i][j] = sum[i][j-1]+  pos[j]  -  pos[(i+j) / 2];
        }
        }
        for(int i = 1; i <= V; ++i){
            dp[i][i] = 0;
            dp[i][1] = sum[1][i];
        }
        for(int j = 2; j <= P; ++j){
            for(int i = j+1; i <= V; ++i){

                dp[i][j] = 9999999;
                for(int k = j-1; k < i; ++k)
                    dp[i][j] = min(dp[i][j],dp[k][j-1]+sum[k+1][i]);
            }
        }

        printf("%d\n",dp[V][P]);
    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