LPS HDOJ 4745 Two Rabbits
/*
题意:一只兔子顺时针跳,另一只逆时针跳,跳石头权值相等而且不能越过起点
LPS:这道就是LPS的应用,把环倍增成链,套一下LPS,然而并不能理解dp[i][i+n-2] + 1,看别人的解题报告吧,以后来补(玩游戏)
详细解释 */
/************************************************
* Author :Running_Time
* Created Time :2015-8-8 16:57:23
* File Name :HDOJ_4747_LPS.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 2e3 + ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ;
int a[MAXN], dp[MAXN][MAXN]; int main(void) { //HDOJ 4745 Two Rabbits
int n;
while (scanf ("%d", &n) == ) {
if (!n) break;
for (int i=; i<=n; ++i) {
scanf ("%d", &a[i]);
a[i+n] = a[i];
}
memset (dp, , sizeof (dp));
for (int i=; i<=*n; ++i) dp[i][i] = ;
for (int i=; i<*n; ++i) {
for (int j=; j+i-<=*n; ++j) {
if (a[j] == a[j+i-]) dp[j][j+i-] = dp[j+][j+i-] + ;
else {
dp[j][j+i-] = max (dp[j+][j+i-], dp[j][j+i-]);
}
}
}
int ans = ;
for (int i=; i<=n; ++i) {
ans = max (ans, dp[i][i+n-]);
ans = max (ans, dp[i][i+n-] + );
}
printf ("%d\n", ans);
} return ;
}
LPS HDOJ 4745 Two Rabbits的更多相关文章
- HDOJ 4745 Two Rabbits DP
Two Rabbits Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Tot ...
- 模拟 HDOJ 4552 Running Rabbits
题目传送门 /* 模拟:看懂题意,主要是碰壁后的转向,笔误2次 */ #include <cstdio> #include <algorithm> #include <c ...
- HDU 4745 Two Rabbits (2013杭州网络赛1008,最长回文子串)
Two Rabbits Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- HDU 4745 Two Rabbits 区间dp_回文序列
题目链接: http://blog.csdn.net/scnu_jiechao/article/details/11759333 Two Rabbits Time Limit: 10000/5000 ...
- HDU 4745 Two Rabbits(区间DP,最长非连续回文子串)
Two Rabbits Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total ...
- HDU 4745 Two Rabbits(最长回文子序列)
http://acm.hdu.edu.cn/showproblem.php?pid=4745 题意: 有一个环,现在有两只兔子各从一个点开始起跳,一个沿顺时针,另一个沿逆时针,只能在一圈之内跳,并且每 ...
- hdu 4745 Two Rabbits 区间DP
http://acm.hdu.edu.cn/showproblem.php?pid=4745 题意: 有两只兔子Tom Jerry, 他们在一个用石头围城的环形的路上跳, Tom只能顺时针跳,Jerr ...
- HDU 4745 Two Rabbits(最长回文子序列)(2013 ACM/ICPC Asia Regional Hangzhou Online)
Description Long long ago, there lived two rabbits Tom and Jerry in the forest. On a sunny afternoon ...
- hdu 4745 Two Rabbits
思路:求最长回文子串的长度!代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #incl ...
随机推荐
- 斯特林(Stirling)公式 求大数阶乘的位数
我们知道整数n的位数的计算方法为:log10(n)+1n!=10^m故n!的位数为 m = log10(n!)+1 lgN!=lg1+lg2+lg3+lg4+lg5+................. ...
- n个点中求任意两点组成斜率的最大值
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1100 首先按x坐标排序,然后相邻的三个点A,B,C 组成的三条直线必然有 ...
- P1547 Out of Hay 洛谷
https://www.luogu.org/problem/show?pid=1547 题目背景 奶牛爱干草 题目描述 Bessie 计划调查N (2 <= N <= 2,000)个农场的 ...
- [Jexus系列] 一、安装并运行 Jexus
注意,本教程使用的jexus版本为5.8.3专业版,操作系统为 Ubunutu 16.04 64位 一.创建默认站点 不熟悉vim的可以看这个: vim超简单入门教程 sudo mkdir -p /v ...
- 【CV论文阅读】An elegant solution for subspace learning
Pre: It is MY first time to see quite elegant a solution to seek a subspace for a group of local fea ...
- log4j-over-slf4j.jar AND slf4j-log4j12.jar 依赖冲突解决方案
使用maven构建项目时,如果项目中有log4j的依赖,在运行程序时可能会出现在同一个类中log4j-over-slf4j.jar和 slf4j-log4j12.jar冲突的问题: 项目报错内容为: ...
- [TypeScript] Use TypeScript’s never Type for Exhaustiveness Checking
TypeScript 2.0 introduced a new primitive type called never, the type of values that never occur. It ...
- Cracking the Coding Interview 150题(二)
3.栈与队列 3.1 描述如何只用一个数组来实现三个栈. 3.2 请设计一个栈,除pop与push方法,还支持min方法,可返回栈元素中的最小值.pop.push和min三个方法的时间复杂度必须为O( ...
- Microsoft Windows CE 5.0 Board Support Package, Boot Loader, and Kernel Startup Sequence
Summary Learn about the initial, low-level startup sequence and the hardware platform functions that ...
- tensorflow,torch tips
apply weightDecay,L2 REGULARIZATION_LOSSES weights = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIAB ...