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

滚动数组实现 375MS 184K 代码,以我的疑问求解答

Posted by zhby1990 at 2010-09-27 17:34:55 on Problem 1159
下面就是我的代码。
这道题我不明白,为什么我不初始化nmin数组,也能AC,是测试数据弱的问题吗?
这都题的边界条件应该是什么?
#include <cstdlib>
#include<stdio.h>
#include<iostream>
#include<string.h>

using namespace std;
short nmin[5005][5005],n;
char c[5005];
/*
 *
 */
int main(int argc, char** argv) {
    int i,j,k;
    while(scanf("%d",&n)!=-1)
    {
        scanf("%s",c+1);
       // memset(nmin,0,sizeof(nmin));
        for(k=1;k<n;k++)
            for(i=1;i+k<=n;i++)
            {
                j=i+k;
                if(c[i]==c[j])nmin[i][j]=nmin[i+1][j-1];
                else
                    nmin[i][j]=1+min(nmin[i+1][j],nmin[i][j-1]);
            }
        printf("%d\n",nmin[1][n]);
    }
    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