| ||||||||||
| 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 | |||||||||
Re:请问,下面代码为什么会Runtime Error ?In Reply To:请问,下面代码为什么会Runtime Error ? Posted by:mmx21 at 2010-12-27 14:17:31 > #include "stdio.h"
> char str[5002];
> int length;
> short f[5002][5002];
>
> void dp() {
> int i,j;
> for(i = length - 2; i >= 0; i--) {
> for(j = i + 1; j < length; j++) {
> if(str[i] == str[j]){
> f[i][j] = f[i+1][j-1];
> } else {
> if(f[i+1][j] < f[i][j-1])
> f[i][j] = f[i+1][j] + 1;
> else
> f[i][j] = f[i][j-1] + 1;
> }
> }
> }
> }
>
> int main() {
> scanf("%d",&length);
> scanf("%s",str);
> dp();
> printf(f[0][length-1]);
> return 0;
> }
同样一段代码,用C++提交结果为什么就对了???
#include <iostream>
using namespace std;
char str[5002];
int length;
short f[5002][5002];
void dp() {
int i,j;
for(i = length - 2; i >= 0; i--) {
for(j = i + 1; j < length; j++) {
if(str[i] == str[j]){
f[i][j] = f[i+1][j-1];
} else {
if(f[i+1][j] < f[i][j-1])
f[i][j] = f[i+1][j] + 1;
else
f[i][j] = f[i][j-1] + 1;
}
}
}
}
int main() {
cin>>length;
cin>>str;
dp();
cout<<(f[0][length-1])<<endl;
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator