题目传送门

 /*
题意:一只兔子顺时针跳,另一只逆时针跳,跳石头权值相等而且不能越过起点
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的更多相关文章

  1. HDOJ 4745 Two Rabbits DP

    Two Rabbits Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Tot ...

  2. 模拟 HDOJ 4552 Running Rabbits

    题目传送门 /* 模拟:看懂题意,主要是碰壁后的转向,笔误2次 */ #include <cstdio> #include <algorithm> #include <c ...

  3. HDU 4745 Two Rabbits (2013杭州网络赛1008,最长回文子串)

    Two Rabbits Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  4. HDU 4745 Two Rabbits 区间dp_回文序列

    题目链接: http://blog.csdn.net/scnu_jiechao/article/details/11759333 Two Rabbits Time Limit: 10000/5000 ...

  5. HDU 4745 Two Rabbits(区间DP,最长非连续回文子串)

    Two Rabbits Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total ...

  6. HDU 4745 Two Rabbits(最长回文子序列)

    http://acm.hdu.edu.cn/showproblem.php?pid=4745 题意: 有一个环,现在有两只兔子各从一个点开始起跳,一个沿顺时针,另一个沿逆时针,只能在一圈之内跳,并且每 ...

  7. hdu 4745 Two Rabbits 区间DP

    http://acm.hdu.edu.cn/showproblem.php?pid=4745 题意: 有两只兔子Tom Jerry, 他们在一个用石头围城的环形的路上跳, Tom只能顺时针跳,Jerr ...

  8. 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 ...

  9. hdu 4745 Two Rabbits

    思路:求最长回文子串的长度!代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #incl ...

随机推荐

  1. Python模块:Re模块、附软件开发目录规范

    Re模块:(正则表达式) 正则表达式就是字符串的匹配规则 正则表达式在多数编程语言里都有相应的支持,Python里面对应的模块时re 常用的表达式规则:(都需要记住) “ . ”   #  默认匹配除 ...

  2. 【Tomcat】tomcat启动后查看运行时JVM参数

    Tomcat优化配置参考http://www.cnblogs.com/qlqwjy/p/8007490.html 1.启动服务后访问localhost,点击Server Status

  3. Canon iP2780/iP2788 清零软件

    http://www.drvsky.com/driver/iP2780_Tools.htm http://www.dyjqd.com/soft/6085.html#download http://v. ...

  4. Linux下搭建maven私服Nexus 3.2.1-01

    1. 私服介绍私服是指私有服务器,是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构建.有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库:否则, ...

  5. Spring 加载类路径外的资源文件

    原文:http://blog.csdn.net/gaofuqi/article/details/46417259 <bean id="propertyConfigurer" ...

  6. [AngularJS] ocLazyLoad -- Lazy loaded module should contain all the dependencies code

    Recentlly works with AngularJS + ocLazyLoad, our project have break down into multi small modules. F ...

  7. [React] Preview and edit a component live with React Live

    In this lesson we'll use React Live to preview and edit a component directly in the browser. React L ...

  8. pageContext 获取Session 为null原因

    问题:在J2EE应用中.发如今自己定义标签中取不到session: HttpSession session = pageContext.getSession(); 你会发现session的值可能是空的 ...

  9. influxDB+telefraf+grafana

    此贴自己记录 下载grafana https://grafana.com/grafana/download?platform=windows 从官网下载influxDB\telefraf的方法 : h ...

  10. CBO之Full Table Scan - FTS算法

    转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/44261859 ************************************** ...