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:动态规划代码如下,注意用short,否则超内存

Posted by licx11 at 2011-08-11 18:14:01 on Problem 1159
In Reply To:动态规划代码如下,注意用short,否则超内存 Posted by:JustName at 2011-08-11 18:09:56
> #include <iostream>
> using namespace std;
> #include <string.h>
> #define N 5001
> int n;
> char s[N];
> short f[N][N];
> int solv(char s[N],int i,int j)
> {
> 	if(f[i][j])
> 		return f[i][j];
> 	if(i >= j)
> 		return f[i][j] = 0;
> 	if(s[i] == s[j])
> 		return f[i][j] = solv(s,i+1,j-1);
> 	if(solv(s,i,j-1) < solv(s,i+1,j))
> 		return f[i][j] = solv(s,i,j-1) + 1;
> 	return f[i][j] = solv(s,i+1,j) + 1;
> }
> int main(void)
> {
> 	scanf("%d",&n);
> 	scanf("%s",s);
> 	memset(f,0,sizeof(f));
> 	printf("%d\n",solv(s,0,strlen(s)-1));
> 	return 0;
> }
严重鄙视用short过的

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