| ||||||||||
| 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 | |||||||||
Why wa, not memory limit error?#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
#define N 5001
int len;
char str[N];
short opt[N][N];
void dynamic()
{
memset( opt, 0, sizeof(opt) );
for( int i = 1; i <= len; i++ )
opt[i][i] = 1;
for( int r = 2; r <= len; r++ )
{
for( int i = 1; i <= len-r+1; i++ )
{
int j = r+i-1;
opt[i][j] = opt[i+1][j] + 1;
if( opt[i][j] > opt[i][j-1]+1 )
opt[i][j] = opt[i][j-1]+1;
int temp = 0;
if( str[i] != str[j] )
temp = 2;
if( opt[i][j] > opt[i+1][j-1]+temp )
{
opt[i][j] = opt[i+1][j-1]+temp;
}
}
}
printf( "%d\n", opt[1][len] );
}
int main()
{
scanf( "%d", &len );
scanf( "%s", str+1 );
dynamic();
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator