4580: [Usaco2016 Open]248

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 255  Solved: 204
[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!
给你n个数,每次可以将两个相邻的相同数x合并成x+1,求最大能合出多少
 

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 鸣谢duan2提供译文

  1. /*
  2. f[i][j]表示合并这段区间最大值
  3. 枚举中间点k,如果f[i][k]==f[k+1][j]且不等于0 就能转移。
  4. */
  5. #include<bits/stdc++.h>
  6.  
  7. #define N 250
  8.  
  9. using namespace std;
  10. int n,ans,f[N][N];
  11.  
  12. int main()
  13. {
  14. scanf("%d",&n);
  15. for (int i=; i<=n; i++)
  16. {
  17. scanf("%d",&f[i][i]);
  18. ans=max(ans,f[i][i]);
  19. }
  20. for (int i=n-; i>=; i--)
  21. for (int j=i+; j<=n; j++)
  22. {
  23. for (int k=i; k<j; k++)
  24. if (f[i][k]==f[k+][j] && f[i][k]!=)
  25. f[i][j]=max(f[i][j],f[i][k]+);
  26. ans=max(ans,f[i][j]);
  27. }
  28. printf("%d",ans);
  29. return ;
  30. }
  1. /*
  2. 题解里这个状态就比较神奇了。
  3. f[i][j]表示到第i个数,得到数值为j,向右合并的最右端点。
  4. 方程f[i][j]=f[f[i][j-1]][j-1];类似倍增。
  5. j比较小,因为两个合并之后得到的数只大1,所以可以跑过去。
  6. */
  7. #include<bits/stdc++.h>
  8.  
  9. #define N 270000
  10.  
  11. using namespace std;
  12. int n,m,ans;
  13. int f[N][],a[N];
  14. int main()
  15. {
  16. freopen("ly.in","r",stdin);
  17. scanf("%d",&n);
  18. for (int i=; i<=n; i++)
  19. {
  20. scanf("%d",&a[i]);
  21. f[i][a[i]]=i+;
  22. }
  23. for (int j=; j<=; j++)
  24. for (int i=; i<=n; i++)
  25. {
  26. if (f[i][j]==) f[i][j]=f[f[i][j-]][j-];
  27. if (f[i][j]>) ans=max(ans,j);
  28. }
  29. printf("%d\n",ans);
  30. return ;
  31. }

bzoj4580: [Usaco2016 Open]248(区间dp)的更多相关文章

  1. 【bzoj4580】[Usaco2016 Open]248 区间dp

    题目描述 Bessie likes downloading games to play on her cell phone, even though she does find the small t ...

  2. BZOJ4580: [Usaco2016 Open]248

    n<=248个数字,可以进行这样的操作:将相邻两个相同的数字合并成这个数字+1,求最大能合成多少. f(i,j)--区间i到j能合成的最大值,f(i,j)=max(f(i,k)+1),f(i,k ...

  3. P3146 [USACO16OPEN]248 (区间DP)

    题目描述  给定一个1*n的地图,在里面玩2048,每次可以合并相邻两个(数值范围1-40),问最大能合出多少.注意合并后的数值并非加倍而是+1,例如2与2合并后的数值为3. 这道题的思路: 状态: ...

  4. 又一道区间DP的题 -- P3146 [USACO16OPEN]248

    https://www.luogu.org/problemnew/show/P3146 一道区间dp的题,以区间长度为阶段; 但由于要处理相邻的问题,就变得有点麻烦; 最开始想了一个我知道有漏洞的方程 ...

  5. 【区间DP】【lgP3146】248

    传送门 Description 给定一个1*n的地图,在里面玩2048,每次可以合并相邻两个(数值范围1-40),问最大能合出多少.注意合并后的数值并非加倍而是+1,例如2与2合并后的数值为3. In ...

  6. 「USACO16OPEN」「LuoguP3146」248(区间dp

    题目描述 Bessie likes downloading games to play on her cell phone, even though she doesfind the small to ...

  7. 「区间DP」「洛谷PP3146 」[USACO16OPEN]248 G

    [USACO16OPEN]248 G 题目: 题目描述 Bessie likes downloading games to play on her cell phone, even though sh ...

  8. 一道另类的区间dp题 -- P3147 [USACO16OPEN]262144

    https://www.luogu.org/problemnew/show/P3147 此题与上一题完全一样,唯一不一样的就是数据范围; 上一题是248,而这一题是262144; 普通的区间dp表示状 ...

  9. 「USACO16OPEN」「LuoguP3147」262144(区间dp

    P3147 [USACO16OPEN]262144 题目描述 Bessie likes downloading games to play on her cell phone, even though ...

随机推荐

  1. oc温习八:static、extern、const 的了解

    参考文章:http://www.cocoachina.com/ios/20161110/18035.html 1.const 这个单词翻译成中文是“常量”的意思.在程序中我们知道“常量”的值是不能变的 ...

  2. oc温习三:常用函数

    参考文章: 算术函数 [算术函数] 函数名 说明 int rand() 随机数生成.(例)srand(time(nil)); //随机数初期化int val = rand()P; //0-49之间的随 ...

  3. P2820 局域网 洛谷

    https://www.luogu.org/problem/show?pid=2820 题目背景 某个局域网内有n(n<=100)台计算机,由于搭建局域网时工作人员的疏忽,现在局域网内的连接形成 ...

  4. Java实现简单的图片浏览器

    第一次写博客,不喜勿喷. 最近一个小师弟问我怎么用Java做图片浏览器,感觉好久没玩Java了,就自己动手做了一下. 学校的教程是用Swing来做界面的,所以这里也用这个来讲. 首先要做个大概的界面出 ...

  5. ArcGIS Engine中的Symbols详解

    转自原文ArcGIS Engine中的Symbols详解 本文由本人翻译ESRI官方帮助文档.尊重劳动成果,转载请注明来源. Symbols ArcObjects用了三种类型的Symbol(符号样式) ...

  6. python字符串连接方法效率比较

    方法1:直接通过加号(+)操作符连接 1 website = 'python' + 'tab' + '.com' 方法2:join方法 1 2 listStr = ['python', 'tab',  ...

  7. 避免使用vector&lt;bool&gt;

     作为一个STL容器,vector<bool>仅仅有两点不正确. 首先.它不是一个STL容器. 其次,它并不存储bool.除此之外.一切正常. 一个对象要成为容器,就必须满足C++标准 ...

  8. vux tabbar 组件

    1.App.vue <!-- 入口文件 --> <template> <div id="app"> <!-- 视图层 --> < ...

  9. Unity 3D 中动态字体的创建

    原创不易,转载请注明转自: http://blog.csdn.net/u012413679/article/details/26232453 ---- kosion 1.载入NGUI插件包,载入完毕后 ...

  10. LoadRunner系列之—-04 录制基于https协议的脚本

    实际性能测试过程中,有些需录制脚本的页面或接口是基于https协议的,按原来方法录制脚本,录完了脚本是空的.为解决这个问题,第一步了解https协议的具体实现,这块网上资料很多,可参考页面下方参考资料 ...