Topic Portal
1 /*2 Test instructions: One rabbit jumps clockwise, the other jumps counterclockwise, and the weight of the stones is equal and cannot cross the starting point .3 LPs: This is the application of LPs, the ring multiplied into a chain, a set of LPS, but do not understand dp[i][i+n-2] + 1, see other people's problem-solving report, to later fill (play the game)4 Detailed explanation5 */6 /************************************************7 * Author:running_time8 * Created time:2015-8-8 16:57:239 * File Name:HDOJ_4747_LPS.cppTen ************************************************/ One A#include <cstdio> -#include <algorithm> -#include <iostream> the#include <sstream> -#include <cstring> -#include <cmath> -#include <string> +#include <vector> -#include <queue> +#include <deque> A#include <stack> at#include <list> -#include <map> -#include <Set> -#include <bitset> -#include <cstdlib> -#include <ctime> in using namespacestd; - to #defineLson L, Mid, RT << 1 + #defineRson mid + 1, R, RT << 1 | 1 -typedefLong Longll; the Const intMAXN = 2e3 +Ten; * Const intINF =0x3f3f3f3f; $ Const intMOD = 1e9 +7;Panax Notoginseng intA[MAXN], DP[MAXN][MAXN]; - the + intMainvoid) {//hdoj 4745, rabbits A intN; the while(SCANF ("%d", &n) = =1) { + if(!n) Break; - for(intI=1; i<=n; ++i) { $scanf ("%d", &a[i]); $A[i+n] =A[i]; - } -Memset (DP,0,sizeof(DP)); the for(intI=1; i<=2*n; ++i) Dp[i][i] =1; - for(intI=2; i<2*n; ++i) {Wuyi for(intj=1; j+i-1<=2*n; ++j) { the if(A[j] = = a[j+i-1]) dp[j][j+i-1] = dp[j+1][j+i-2] +2; - Else { Wudp[j][j+i-1] = max (dp[j+1][j+i-1], dp[j][j+i-2]); - } About } $ } - intAns =0; - for(intI=1; i<=n; ++i) { -ans = max (ans, dp[i][i+n-1]); Aans = max (ans, dp[i][i+n-2] +1); + } theprintf ("%d\n", ans); - } $ the return 0; the}
LPS hdoj 4745-Rabbits