| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
贴个一维的滚动数组(C++提交 156K)真是不明白为啥用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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator