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 |
最水dpMLE 改成short AC#include <iostream> #include <memory.h> using namespace std; short dp[5001][5001]; int min(int a,int b) { if(a<=b) return a; else return b; } int main() { char str[5001]; int num; cin>>num; for(int i=1;i<=num;i++) cin>>str[i]; //初始化 for(int i=1;i<=num;i++) { dp[0][i]=num-i+1; } for(int i=1;i<=num;i++) { dp[i][num+1]=i; } for(int i=1;i<=num;i++) { for(int j=num;j>=i;j--) { if(str[i]==str[j]) dp[i][j]=dp[i-1][j+1]; else dp[i][j]=9999; dp[i][j]=min(dp[i][j],dp[i-1][j]+1); dp[i][j]=min(dp[i][j],dp[i][j+1]+1); } } int minnum=32766; for(int i=1;i<=num;i++) { minnum=min(dp[i][i+1],minnum); minnum=min(minnum,dp[i][i]); } cout<<minnum; //system("pause"); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator