bzoj4580: [Usaco2016 open]248 time limit:10 Sec Memory limit:128 MB
Submit:23 solved:21
[Submit] [Status] [Discuss] Descriptionbessie likes downloading games for play on her cell phone, even though she does find the small touch screen rath Er cumbersome to use with her large hooves. She is particularly intrigued by the current game she is playing. The game starts with a sequence of NN positive integers (2≤n≤248), each in the range 1 ... In one move, Bessie can take the adjacent numbers with equal values and replace them a single number of value one Grea ter (e.g., she might replace, 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!
Inputthe 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 Input4
1
1
1
2Sample Output3
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 isn't optimal to join the first and the 1s.HINT Source
Obviously we can range DP ...
1#include <bits/stdc++.h>2 #defineRep (i,l,r) for (int i=l;i<=r;i++)3 #defineN 3004 intn,ans,s[n],f[n][n],j;5 using namespacestd;6 intMain () {7scanf"%d", &n); Rep (I,1, N) scanf ("%d", &s[i]), ans=Max (ans,s[i]);8Rep (I,1, N) f[i][i]=S[i];9Rep (Len,2, N) for(intI=1; i+len-1<=n;i++) {Tenj=i+len-1; Onef[i][j]=-1; ARep (k,i,j-1)if(f[i][k]==f[k+1][J]) F[i][j]=max (f[i][j],f[i][k]+1); -ans=Max (ans,f[i][j]); - } thecout<<ans; -}
View Code
bzoj4580: [Usaco2016 open]248