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 |
刚刚发了一遍。。。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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator