bzoj 4580: [Usaco2016 Open]248

来源:互联网 发布:猎聘 JAVA 编程题 编辑:程序博客网 时间:2024/06/08 11:03

4580: [Usaco2016 Open]248

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 131  Solved: 105
[Submit][Status][Discuss]

Description

Bessie likes downloading games to play on her cell phone, even though she does find the small touch 
screen rather cumbersome to use with her large hooves.She is particularly intrigued by the current g
ame she is playing. The game starts with a sequence of NN positive integers (2≤N≤248), each in the
 range 1…40. In one move, Bessie can take two adjacent numbers with equal values and replace them a
 single number of value one greater (e.g., she might replace two adjacent 7s with an 8). The goal is
 to maximize the value of the largest number present in the sequence at the end of the game. Please 
help Bessie score as highly as possible!

Input

The first line of input contains N, and the next N lines give the sequence of N numbers at the start
 of the game.

Output

Please output the largest integer Bessie can generate.

Sample Input

4
1
1
1
2

Sample Output

3
//In this example shown here, Bessie first merges the second and third 1s to obtain the sequence 1 2 2
, and then she merges the 2s into a 3. Note that it is not optimal to join the first two 1s.

HINT

Source

Gold





【分析】

签到题第三弹...

真的。没有1A的题,全都是2A,我今天脑子一定瓦特了。

用的是区间DP,不过我赌五毛贪心可以O(n)



【代码】

#include<iostream>#include<cstring>#include<cstdio>#define ll long long#define M(a) memset(a,0,sizeof a)#define fo(i,j,k) for(i=j;i<=k;i++)using namespace std;const int mxn=250;int n,m,ans;int dp[mxn][mxn];inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+ch-'0',ch=getchar();return x*f;}int main(){int i,j,k;n=read();fo(i,1,n) dp[i][i]=read();fo(k,1,n)  fo(i,1,n) if(i+k<=n)    fo(j,i,i+k-1)    {    if(dp[i][j]==dp[j+1][i+k])      dp[i][i+k]=max(dp[i][i+k],dp[i][j]+1);    ans=max(ans,dp[i][i+k]);}printf("%d\n",ans);return 0;}/*81 1 1 1 1 1 1 1*/


原创粉丝点击