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 |
滚动数组实现 375MS 184K 代码,以我的疑问求解答下面就是我的代码。 这道题我不明白,为什么我不初始化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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator