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 |
菜鸟也顺利通过。#include <stdio.h> #include <string.h> int dp[3][5000]; int min(int a,int b) { return a<b?a:b; } int main() { int len; char s[5001]; while(scanf("%d",&len)!=EOF) { scanf("%s",s); memset(dp,0,sizeof(dp)); for(int k=1;k<len;k++) { for(int i=0;i<len;i++) { dp[0][i]=dp[1][i]; dp[1][i]=dp[2][i]; } for(int i=0;i+k<len;i++) { if(s[i]==s[i+k]) { if(k==1) dp[2][i]=0; else dp[2][i]=dp[0][i+1]; } else { dp[2][i]=min(dp[1][i],dp[1][i+1])+1; } } } printf("%d\n",dp[2][0]); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator