题目链接:

http://blog.csdn.net/scnu_jiechao/article/details/11759333

Two Rabbits

Time Limit: 10000/5000 MS (Java/Others)
Memory Limit: 65535/65535 K (Java/Others)
#### 问题描述
> Long long ago, there lived two rabbits Tom and Jerry in the forest. On a sunny afternoon, they planned to play a game with some stones. There were n stones on the ground and they were arranged as a clockwise ring. That is to say, the first stone was adjacent to the second stone and the n-th stone, and the second stone is adjacent to the first stone and the third stone, and so on. The weight of the i-th stone is ai.
>
> The rabbits jumped from one stone to another. Tom always jumped clockwise, and Jerry always jumped anticlockwise.
>
> At the beginning, the rabbits both choose a stone and stand on it. Then at each turn, Tom should choose a stone which have not been stepped by itself and then jumped to it, and Jerry should do the same thing as Tom, but the jumping direction is anti-clockwise.
>
> For some unknown reason, at any time , the weight of the two stones on which the two rabbits stood should be equal. Besides, any rabbit couldn't jump over a stone which have been stepped by itself. In other words, if the Tom had stood on the second stone, it cannot jump from the first stone to the third stone or from the n-the stone to the 4-th stone.
>
> Please note that during the whole process, it was OK for the two rabbits to stand on a same stone at the same time.
>
> Now they want to find out the maximum turns they can play if they follow the optimal strategy.
#### 输入
> The input contains at most 20 test cases.
> For each test cases, the first line contains a integer n denoting the number of stones.
> The next line contains n integers separated by space, and the i-th integer ai denotes the weight of the i-th stone.(1 The input ends with n = 0.
#### 输出
> For each test case, print a integer denoting the maximum turns.
####样例输入
> 1
> 1
> 4
> 1 1 2 1
> 6
> 2 1 1 2 1 3
> 0

样例输出

1

4

5

题意

给你一个环,一个人任选一点顺时针跳,另一个人也任选一点逆时针跳,两个人的起点可以相同,每回合每个人向前条一次,现在跳的时候有两个要求:1、两个人每次跳的位置上的数字必须相同,2、跳的最远位置不能超过一圈。

求最大的回合数

题解

Portal

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
#include<cstdio>
#include<string>
#include<bitset>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define X first
#define Y second
#define mkp make_pair
#define lson (o<<1)
#define rson ((o<<1)|1)
#define mid (l+(r-l)/2)
#define sz() size()
#define pb(v) push_back(v)
#define all(o) (o).begin(),(o).end()
#define clr(a,v) memset(a,v,sizeof(a))
#define bug(a) cout<<#a<<" = "<<a<<endl
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define scf scanf
#define prf printf typedef int LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<pair<int,int> > VPII; const int INF=0x3f3f3f3f;
const LL INFL=0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-8;
const double PI = acos(-1.0); //start---------------------------------------------------------------------- const int maxn=2222; int n;
int a[maxn];
int dp[maxn][maxn]; int main() {
while(scf("%d",&n)==1&&n){
for(int i=0;i<n;i++) scf("%d",&a[i]);
// rep(i,0,len) prf("%d ",a[i]); puts(""); clr(dp,0);
for(int r=0;r<n;r++){
for(int l=r;l>=0;l--){
if(l==r) dp[l][r]=1;
else{
if(a[l]==a[r]){
dp[l][r]=max(dp[l][r],dp[l+1][r-1]+2);
}
dp[l][r]=max(dp[l][r],dp[l][r-1]);
dp[l][r]=max(dp[l][r],dp[l+1][r]);
}
}
}
int ans=dp[0][n-1];
for(int i=0;i<n-1;i++) ans=max(ans,dp[0][i]+dp[i+1][n-1]); prf("%d\n",ans);
}
return 0;
} //end-----------------------------------------------------------------------

HDU 4745 Two Rabbits 区间dp_回文序列的更多相关文章

  1. hdu 4745 Two Rabbits 区间DP

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

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

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

  3. HDU 4745 Two Rabbits ★(最长回文子序列:区间DP)

    题意 在一个圆环串中找一个最长的子序列,并且这个子序列是轴对称的. 思路 从对称轴上一点出发,向两个方向运动可以正好满足题意,并且可以证明如果抽选择的子环不是对称的话,其一定不是最长的. 倍长原序列, ...

  4. HDU 4745 Two Rabbits (区间DP)

    题意: 两只兔子,在一个由n块石头围成的环上跳跃,每块石头有一个权值ai.开始时两兔站在同一石头上(也算跳1次),一只从左往右跳,一只从右往左跳,两只同时跳,而每跳一次,两只兔子所站的石头的权值都要相 ...

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

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

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

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

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

  8. hdu 4745 Two Rabbits

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

  9. 杭州网赛 two rabbits (hdu 4745)

    算法很简单,问题是,怎么证明,答案是回文序列. 设a,b走的序列按顺时针是: a1 , a2 , a3 , ... , ak b1 , b2 , b3 , ... , bk 考虑端点的2种情况: 1. ...

随机推荐

  1. jQuery----JQuery动画(hide()和show())(下)

    本文是对hide()和show()的进一步补充,其中不仅介绍回调函数,还有递归的相关知识点. 案例要求: 点击”隐藏动画“按钮,四个头像从后向前,每个以0.8秒的速度消失 点击”显示动画“按钮,四个头 ...

  2. Linux学习笔记(第六章)

    第六章-档案权限与目录配置#chgrp:改变档案的所属群组#chown:改变档案的拥有者#chmod:改变档案的权限及属性 chown用法 chmod用法: r:4 w:2 x:1对于文档: 对于目录 ...

  3. Windows 视频Directshow开发介绍

    在Windows平台上实现一个文件播放器有什么好的开发库和方案呢?方案有很多,比如基于FFmpeg,VLC的插件,mplayer,Directshow.用FFmpeg来实现文件格式解析.分离视频音频流 ...

  4. python学习之路(1)

    今天刚入门python,对于有c和java基础的我,学习起来还是比较容易的,我并没有用PyCharm写,而是最基础的IDLE,学习python比java容易的地方就是不要写分号,不要打包,不要定义等等 ...

  5. 20155236范晨歌 Exp1PC平台逆向破解及Bof基础实践

    出现的问题及解决: 在下载execstack时,出现了下列签名无效的错误! 解决方案:发现是密钥过期了,将新的密钥填入apt-keyring 输入命令:apt-key adv --keyserver ...

  6. 几种交叉验证(cross validation)方式的比较

    模型评价的目的:通过模型评价,我们知道当前训练模型的好坏,泛化能力如何?从而知道是否可以应用在解决问题上,如果不行,那又是哪里出了问题? train_test_split 在分类问题中,我们通常通过对 ...

  7. 【BZOJ1041】[HAOI2008]圆上的整点

    [BZOJ1041][HAOI2008]圆上的整点 题面 bzoj 洛谷 题解 不妨设\(x>0,y>0\) \[ x^2+y^2=r^2\\ y^2=(x+r)(x-r) \] 设\(r ...

  8. SSISDB3:Package的执行实例

    SSISDB 系列随笔汇总: SSISDB1:使用SSISDB管理Package SSISDB2:SSIS工程的操作实例 SSISDB3:Package的执行实例 SSISDB4:当前正在运行的Pac ...

  9. Async方法死锁的问题 Don't Block on Async Code(转)

    今天调试requet.GetRequestStreamAsync异步方法出现不返回的问题,可能是死锁了.看到老外一篇文章解释了异步方法死锁的问题,懒的翻译,直接搬过来了. http://blog.st ...

  10. String.valueOf(object).trim())

    获得对象的字段的值,然后转成string类型,并且去掉前后空白~~ToString()是转化为字符串的方法 Trim()是去两边空格的方法把StringBuffer转换成String类型时 没有用.t ...