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

Why wa, not memory limit error?

Posted by anne2277 at 2005-06-30 10:32:41 on Problem 1159
#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:
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