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

刚刚发了一遍。。。

Posted by smilerxz at 2009-08-04 23:07:25 on Problem 1159
In Reply To:Re:此题为最基本的动态规划。思路如下。 Posted by:777888999 at 2009-08-04 21:37:13
部分代码如下:
//c[5001][5001]
    for (int i = 0; i < 2; i++)
        c[0][i] = c[i][0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (s[i] == s[N - j - 1])
                c[i + 1][j + 1] = c[i][j] + 1;
            else if (c[i + 1][j] >= c[i][j + 1])
                c[i + 1][j + 1] = c[i + 1][j];
            else c[i + 1][j + 1] = c[i][j + 1];
        }
    }

//c[2][5001]
    for (int i = 0; i <= N; i++)
        c[0][i] = 0;
    c[1][0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (s[i] == s[N - j - 1])
                c[1][j + 1] = c[0][j] + 1;
            else if (c[1][j] >= c[0][j + 1])
                c[1][j + 1] = c[1][j];
            else c[1][j + 1] = c[0][j + 1];
        }
        memcpy(c[0], c[1], (N + 1) * sizeof(int));
    }

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