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

高手们300+,400+MS是怎么弄的啊?我觉得我这DP代码已经很精简了,还要500+……

Posted by qinpxi at 2010-12-07 16:26:56 on Problem 1159 and last updated at 2010-12-07 16:29:20
#include <stdio.h>
#include <memory.h>

#define MAXN 5001
#define min(x,y) ((x) < (y) ? (x) : (y))
int s[2][MAXN];

int main() {
	char a[MAXN];
	int n;
	
	scanf("%d\n%s", &n, a);
	
	for (int k=2; k<=n; k++) {
		int k1 = k&1;
		int k2 = (k+1)&1;
		for (int i=0; i<=n-k; i++) {
			int j=i+k-1;
			if (a[i] == a[j])
				s[k1][i] = s[k1][i+1];
			else
				s[k1][i] = min(s[k2][i], s[k2][i+1]) + 1;
		}
	}
	printf("%d\n", s[n&1][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