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 |
为什么dp数组定义在函数里面就RE,定义成全局变量就AC了#include <iostream> #include <cstdio> #include <cstring> #define N 5002 using namespace std; short dp[N][N]; int main() { int n; while(cin>>n) { char *str1=new char[n+1]; char *str2=new char[n+1]; cin>>str1; int i,j; for(i=0;i<n;i++) str2[i]=str1[n-i-1]; str2[i]='\0'; memset(dp,0,sizeof(dp)); for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(str1[i]==str2[j]) dp[i+1][j+1]=dp[i][j]+1; else dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]); } } cout<<n-dp[n][n]<<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