n<=248个数字,可以进行这样的操作:将相邻两个相同的数字合并成这个数字+1,求最大能合成多少。

f(i,j)--区间i到j能合成的最大值,f(i,j)=max(f(i,k)+1),f(i,k)=f(k+1,j)。

 #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
#include<math.h>
//#include<iostream>
using namespace std; int n;
#define maxn 311
int f[maxn][maxn];
int main()
{
scanf("%d",&n);
int ans=;
for (int i=;i<=n;i++) scanf("%d",&f[i][i]),ans=max(ans,f[i][i]);
for (int len=;len<n;len++)
for (int i=,j=i+len;j<=n;i++,j++)
{
f[i][j]=-;
for (int k=i;k<j;k++)
if (f[i][k]==f[k+][j]) f[i][j]=max(f[i][j],f[i][k]+);
ans=max(ans,f[i][j]);
}
printf("%d\n",ans);
return ;
}

BZOJ4580: [Usaco2016 Open]248的更多相关文章

  1. bzoj4580: [Usaco2016 Open]248(区间dp)

    4580: [Usaco2016 Open]248 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 255  Solved: 204[Submit][S ...

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

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

  3. BZOJ4580/Luogu3147 [Usaco2016 Open]248

    amazing #include <iostream> #include <cstdio> #include <cstring> #include <algo ...

  4. 4580: [Usaco2016 Open]248

    Description Bessie likes downloading games to play on her cell phone, even though she does find the ...

  5. BZOJ 4580: [Usaco2016 Open]248

    Description 一个序列,每次可以把相邻的两个数合为一个,价值+1,求最后的最大价值. Sol 区间DP. \(f[i][j]\) 表示 \(i-j\) 中合成一个数字为多少,转移就是枚举断点 ...

  6. bzoj Usaco补完计划(优先级 Gold>Silver>资格赛)

    听说KPM初二暑假就补完了啊%%% 先刷Gold再刷Silver(因为目测没那么多时间刷Silver,方便以后TJ2333(雾 按AC数降序刷 ---------------------------- ...

  7. BZOJ 4576: [Usaco2016 Open]262144

    Description 一个序列,每次可以将两个相同的数合成一个数,价值+1,求最后最大价值 \(n \leqslant 262144\) Sol DP. 这道题是 BZOJ 4580: [Usaco ...

  8. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  9. 【BZOJ 4580】【Usaco2016 Open】248

    http://www.lydsy.com/JudgeOnline/problem.php?id=4580 区间dp,f(i,j)表示区间[i,j]全部合成一个数,这个数是多少. 可以归纳证明[i,j] ...

随机推荐

  1. JS通过使用PDFJS实现基于文件流的预览功能

    需求: 使用JS实现PDF文件预览功能 备选方案: 使用ViewerJS,官网  http://viewerjs.org/ 使用PDFJS,官网  https://mozilla.github.io/ ...

  2. HashMap详解 基于jdk1.7

    转载自:http://zhangshixi.iteye.com/blog/672697 1.    HashMap概述: HashMap是基于哈希表的Map接口的非同步实现.此实现提供所有可选的映射操 ...

  3. cyclic swapping algorithm

    原文见:https://leetcode.com/problems/couples-holding-hands/discuss/113362/JavaC%2B%2B-O(N)-solution-usi ...

  4. swift 泛型的类型约束

    总结: 1.类型约束只能添加到泛型参量上面 2.关联类型是泛型参量: 3.关联类型可以通过 协议.关联类型名称的形式引用: func allItemsMatch<C1: Container, C ...

  5. 【转载】用Python实现端口映射功能(A/B/C内外网)

    转载地址 :http://hutaow.com/blog/2014/09/08/write-tcp-mapping-program-with-python/ 有A,B,C三台计算机,A,B互通,B,C ...

  6. && (and)、||(or) 条件语句

    当前面条件满足时,就执行后面的代码 //条件为真时,就执行其中的语句 if($a>0){ $b='This is test'; } //上面的写法太麻烦,可以这样简写 $a>0 & ...

  7. python猜年龄游戏升级版

    猜年龄游戏升级版 要求:允许用户最多尝试3次,每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y,就继续让其猜3次,以此往复,如果回答N,就退出程序,如何猜对了,就直接退出 age = 1 ...

  8. VR技术在数据中心3D机房中的应用(上)

    VR技术在数据中心3D机房中的应用(上)   前两天跟朋友A吃饭,吃着吃着就说到了VR.近几年来,VR技术越来越火,感觉能跟VR沾点边的都特别高大上,朋友A也是,一提到VR,就怎么都掩盖不住他发自肺腑 ...

  9. jvm 内存溢出 在myeclipse中加大tomcat的jvm内存 java.lang.OutOfMemoryError: PermGen space

    使用myeclipse启动两个SSH2的部署在tomcat6下的项目 报出java.lang.OutOfMemoryError: PermGen space 解决办法: 在myeclipse中加大jv ...

  10. linux 如何查看硬盘大小,内存大小等系统信息及硬件信息

    一.linux CPU大小[root@idc ~]# cat /proc/cpuinfo |grep "model name" && cat /proc/cpuin ...