博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 4745 Two Rabbits (2013杭州网络赛1008,最长回文子串)
阅读量:7251 次
发布时间:2019-06-29

本文共 3719 字,大约阅读时间需要 12 分钟。

Two Rabbits

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)

Total Submission(s): 505    Accepted Submission(s): 260

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

 

Input
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 <= n <= 1000, 1 <= ai <= 1000)
The input ends with n = 0.
 

 

Output
For each test case, print a integer denoting the maximum turns.
 

 

Sample Input
1 1 4 1 1 2 1 6 2 1 1 2 1 3 0
 

 

Sample Output
1 4 5
Hint
For the second case, the path of the Tom is 1, 2, 3, 4, and the path of Jerry is 1, 4, 3, 2. For the third case, the path of Tom is 1,2,3,4,5 and the path of Jerry is 4,3,2,1,5.
 

 

Source
 

 

Recommend
liuyiding
 

 

 

答案竟然就是分成两部分以后的最长回文子串,

太难想到了,TAT

 

 

1 /* *********************************************** 2 Author        :kuangbin 3 Created Time  :2013/9/15 星期日 15:20:03 4 File Name     :2013杭州网络赛\1008.cpp 5 ************************************************ */ 6  7 #pragma comment(linker, "/STACK:1024000000,1024000000") 8 #include 
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 #include
16 #include
17 #include
18 #include
19 #include
20 using namespace std;21 #define REP(I, N) for (int I=0;I
=int(A);--I)24 #define REP_1(I, N) for (int I=1;I<=int(N);++I)25 #define FOR_1(I, A, B) for (int I=int(A);I<=int(B);++I)26 #define DWN_1(I, B, A) for (int I=int(B);I>=int(A);--I)27 #define REP_C(I, N) for (int N____=int(N),I=0;I
=A____;--I)30 #define REP_1_C(I, N) for (int N____=int(N),I=1;I<=N____;++I)31 #define FOR_1_C(I, A, B) for (int B____=int(B),I=A;I<=B____;++I)32 #define DWN_1_C(I, B, A) for (int A____=int(A),I=B;I>=A____;--I)33 #define DO(N) while(N--)34 #define DO_C(N) int N____ = N; while(N____--)35 #define TO(i, a, b) int s_=a
<= n;i++)51 scanf("%d",&a[i]);52 memset(dp,0,sizeof(dp));53 for(int i = 1;i <= n;i++)dp[i][i] = 1;54 for(int k = 1;k <= n;k++)55 for(int i = 1;i + k <= n;i++)56 {57 dp[i][i+k] = max(dp[i+1][i+k],dp[i][i+k-1]);58 if(a[i] == a[i+k])dp[i][i+k] = max(dp[i][i+k],2+dp[i+1][i+k-1]);59 }60 int ans = 0;61 for(int i = 1;i <= n;i++)62 ans = max(ans,dp[1][i]+dp[i+1][n]);63 printf("%d\n",ans);64 }65 return 0;66 }

 

 

 

 

 

 

转载地址:http://kphbm.baihongyu.com/

你可能感兴趣的文章
Unity3D教程:iTween插件的介绍和用法
查看>>
zabbix监控磁盘IO
查看>>
Linux inode分析
查看>>
ospf 区域类型详细
查看>>
Linux下Bash编程之條件判斷详解(二)
查看>>
模板引擎缓存
查看>>
php 5.6.11添加模块
查看>>
手动切换和自动切换图片 js代码
查看>>
matlab-线性代数 根据二次型写矩阵
查看>>
flutter 环境搭建
查看>>
Win 7 deskhelp
查看>>
移动端固定底部-ios中钉钉解决方法
查看>>
textbox设置样式为空背景色透明
查看>>
Sybase SQL Anywhere 7 数据库修复成功
查看>>
发展到1Gbps及其以上的速度
查看>>
TurboMail智慧协同通讯平台
查看>>
TurboMail为企业提供海量投递邮件群发系统
查看>>
Linux系统命令Cut使用
查看>>
我的友情链接
查看>>
MySQL 游标(cursor)简单应用
查看>>