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

错了N次,看了网上牛人的解法,终于AC了(动态规划+滚动数组)

Posted by ryzasia at 2010-03-22 16:37:56 on Problem 1159
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <list>
#include <map>
#include <set>
using namespace std;

char str[5001];
short DP[2][5001],len,i,j;

int main()
{     

    scanf("%d\n%s",&len,str+1);
        
    for(i = 1;i <= len;++i)
      for(j = 1;j <= len;++j)
      {
        if(str[i] == str[len-j+1])
          DP[i%2][j] = DP[(i-1)%2][j-1] + 1;
        else
          DP[i%2][j] = DP[(i-1)%2][j]>DP[i%2][j-1] ? DP[(i-1)%2][j] : DP[i%2][j-1];      
      }
    printf("%d\n",len-DP[len%2][len]);
  

    system("pause");
    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