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

这样DP为什么WA

Posted by Da_corleane at 2010-04-03 22:00:04 on Problem 3422
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 60
int n, m;
int board[N][N], pnt[N*N], dp[N*N];

int main( ){
	int i, j, k, ans;
	int u, v;
	while ( scanf( "%d%d", &n, &m ) != EOF ){
		for ( i = 0; i < n; i++ ) for ( j = 0; j < n; j++ ) scanf( "%d", &board[i][j] );
		ans = 0;
		for ( k = 0; k < m; k++ ){
			memset( pnt, -1, sizeof(pnt) );
			memset( dp, 0, sizeof(dp) );
			for ( i = 0; i < n; i++ ){
				for ( j = 0; j < n; j++ ){
					u = i*n+j;
					dp[u] += board[i][j];
					if ( j+1 < n ){
						v = u+1;
						if ( dp[v] < dp[u] ){
							pnt[v] = u;
							dp[v] = dp[u];
						}
					}
					if ( i+1 < n ){
						v = u+n;
						if ( dp[v] < dp[u] ){
							pnt[v] = u;
							dp[v] = dp[u];
						}
					}
				}
			}
			if ( dp[n*n-1] < 0 ) break;
			ans += dp[n*n-1];
			for ( u = n*n-1; u != -1; u = pnt[u] ){
				i = u/n;
				j = u%n;
				board[i][j] = 0;
			}
		}
		printf( "%d\n", ans );
	}
}

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