bzoj 4580: [Usaco2016 Open]248
来源:互联网 发布:猎聘 JAVA 编程题 编辑:程序博客网 时间:2024/06/08 11:03
4580: [Usaco2016 Open]248
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 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
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.
//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*/
阅读全文
1 0
- BZOJ 4580: [Usaco2016 Open]248
- bzoj 4580: [Usaco2016 Open]248
- bzoj 4580: [Usaco2016 Open]248 (dp)
- [DP || 贪心 链表] BZOJ 4576 [Usaco2016 Open]262144 & BZOJ 4580 [Usaco2016 Open]248
- 4580: [Usaco2016 Open]248
- BZOJ4580 [Usaco2016 Open]248
- BZOJ4580: [Usaco2016 Open]248
- bzoj 4586: [Usaco2016 Open]Landscaping 堆
- bzoj 4578 [Usaco2016 OPen]Splitting the Field
- bzoj 4579 [Usaco2016 Open]Closing the Farm
- BZOJ 4582: [Usaco2016 Open]Diamond Collector
- BZOJ4580: [Usaco2016 Open]248 dp
- bzoj 4581: [Usaco2016 Open]Field Reduction (dfs)
- 【bzoj 4581】[Usaco2016 Open]Field Reduction(dfs)
- [BZOJ4580][Usaco2016 Open]248(dp)
- bzoj4576【Usaco2016 Open】262144
- [Usaco2016 Open]Field Reduction
- BZOJ4586: [Usaco2016 Open]Landscaping
- TCP/IP详解--拥塞控制 & 慢启动 快恢复 拥塞避免
- web service实例
- 入门 Webpack,看这篇就够了
- Hexo+GitHub 搭建静态个人博客
- 算法导论 练习题 14.1-7(逆序对)
- bzoj 4580: [Usaco2016 Open]248
- python ggplot使用文档(1)
- Stemwin外置图片制作
- 【如何快速的开发一个完整的iOS直播app】(推流篇)
- Leetcode 22(Java)
- 前端基础进阶(一):内存空间详细图解
- Lucas学习
- deepwalk遇到RuntimeError on windows trying python multiprocessing问题解决办法
- Maven 创建Spring MVC 工程简单例子