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

贴个一维的滚动数组(C++提交 156K)

Posted by lovai at 2010-11-27 14:21:04 on Problem 1159 and last updated at 2010-11-27 14:32:30
真是不明白为啥用C++提交内存占用少几百k,oj是怎么算出内存消耗的啊 难道不仅和实际使用的有关还和编译系统有很大关系??
#include <stdio.h>
#include <string.h>
int main()
{	
	char a[5002];
	int f[5002];
    int i,j,n,t,tp;
    scanf("%d%s",&n,a+1);

	memset(f,0,sizeof(f));
    for(i=1;i<=n;i++){
		tp=0;	//f[i-1,j-1]复位,一开始忘记了,老是wa,郁闷
		for(j=n;j>=1;j--){
			if(a[i]==a[j]){
				t=f[j];
				f[j]=tp+1;	//f[i,j]=f[i-1,j-1]+1
				tp=t;		
			}
			else{
				tp=f[j];
				if(f[j]<f[j+1]) f[j]=f[j+1]; //f[i-1,j]<f[i,j-1]
			}
		}
    }
    printf("%d\n",n-f[1]);
    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