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 ...
随机推荐
- 【small项目】MySQL第二天早上第一次连接超时报错,解决方法com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
MySQL第二天早上第一次连接超时报错,解决方法com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link ...
- 2017-10-01-morning
T1 位运算1(bit) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK拥有一个十进制的数N.它赋予了N一个新的意义:将N每一位都拆开来后再加起来就是N ...
- Mycat环境搭建教程收集(待实践)
先收集,后续再实践. http://blog.csdn.net/dreamcode/article/details/44307377 http://blog.csdn.net/lanonola/art ...
- Vue.js父子通信之所有方法和数据共享
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Android GIS开发系列-- 入门季(14)FeatureLayer之范围查询
Android GIS开发系列-- 入门季(5),这篇文章中,我们知道如何去查找要素.现在有一个需求,查找某点5000米范围的要素,那如何来做呢?首先我们需要在地图上画个5000米半径的圆,然后根据Q ...
- 冲刺Offer - 二叉树的深度
https://www.nowcoder.net/practice/435fb86331474282a3499955f0a41e8b?tpId=13&tqId=11191&tPage= ...
- 链表倒置,这个还是考验仔细程度,第一遍还没做对 —— 剑指Offer
https://www.nowcoder.net/practice/75e878df47f24fdc9dc3e400ec6058ca?tpId=13&tqId=11168&tPage= ...
- Windows Server 2012关机的几种方法
综合使用方法如下: 1.shutdown -r –f 強制重新启动 2.shutdown –s –f 強制关闭 方法/步骤 1 首先把鼠标移到任务栏右下角,时间往右一点小空位,稍微停留一 ...
- centos 命令行中 * 和 . 的区别
錯誤 cp /home/test1/* /home/test2/ –a 用參數*將不可以複製linux中.開頭的隱藏文件 正確 cp /home/test1/. home ...
- [Spring] Properties for project configuration
We might have some project specific configuration need to setup. The good approach to do this in Spr ...