| ||||||||||
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 |
any fantastic skill? My prog got TLE.#include <iostream> #include <cstdlib> #include <string> using namespace std; int main() { int n; int i; string x,y; while ( cin >> n) { cin >> x; y = x; int len = x.length(); for (i = 0; i <= (len-1)/2; i++) { int tmp = y[i]; y[i] = y[len-1-i]; y[len-1-i] = tmp; } int m = x.length(), l = y.length(); short c[2][5001]; int i,j; for (j = 0; j <= l; j++) c[0][j] = 0; c[1][0] = 0; for (i = 1; i <= m; i++) for (j = 1; j <= l; j++) { if (x[i-1] == y[j-1]) c[i % 2][j] = c[(i+1) % 2][j-1]+1; else if (c[i % 2][j-1] >= c[(i+1) % 2][j]) c[i % 2][j] = c[i % 2][j-1]; else c[i % 2][j] = c[(i+1) % 2][j]; } cout << n - c[m % 2][l] << endl; } system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator