BZOJ 4580: [Usaco2016 Open]248
Description
一个序列,每次可以把相邻的两个数合为一个,价值+1,求最后的最大价值.
Sol
区间DP.
\(f[i][j]\) 表示 \(i-j\) 中合成一个数字为多少,转移就是枚举断点,断点两边的价值一样,就合并.
复杂度 \(O(n^3)\)
Code
/**************************************************************
Problem: 4580
User: BeiYu
Language: C++
Result: Accepted
Time:308 ms
Memory:1544 kb
****************************************************************/ #include <cstdio>
#include <cstring>
#include <iostream>
using namespace std; const int N = 255;
const int M = 50; int n,ans;
int a[N];
int f[N][N]; inline int in(int x=0){ scanf("%d",&x);return x; }
int DFS(int l,int r){
if(l == r) return f[l][r]=a[l];
if(~f[l][r]) return f[l][r];
f[l][r]=0;
for(int i=l;i<r;i++){
int x=DFS(l,i),y=DFS(i+1,r);
if(x!=0 && y!=0 && x == y) f[l][r]=max(f[l][r],x+1);
}ans=max(ans,f[l][r]);return f[l][r];
}
int main(){
n=in();
for(int i=1;i<=n;i++) a[i]=in(),ans=max(ans,a[i]); memset(f,0xff,sizeof(f)); for(int i=1;i<=n;i++) for(int j=i;j<=n;j++) DFS(i,j); // for(int i=1;i<=n;i++) for(int j=i;j<=n;j++) cout<<i<<" "<<j<<" "<<DFS(i,j)<<endl; cout<<ans<<endl;
return 0;
}
BZOJ 4580: [Usaco2016 Open]248的更多相关文章
- 4580: [Usaco2016 Open]248
Description Bessie likes downloading games to play on her cell phone, even though she does find the ...
- BZOJ 4576: [Usaco2016 Open]262144
Description 一个序列,每次可以将两个相同的数合成一个数,价值+1,求最后最大价值 \(n \leqslant 262144\) Sol DP. 这道题是 BZOJ 4580: [Usaco ...
- bzoj4580: [Usaco2016 Open]248(区间dp)
4580: [Usaco2016 Open]248 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 255 Solved: 204[Submit][S ...
- 【BZOJ 4580】【Usaco2016 Open】248
http://www.lydsy.com/JudgeOnline/problem.php?id=4580 区间dp,f(i,j)表示区间[i,j]全部合成一个数,这个数是多少. 可以归纳证明[i,j] ...
- BZOJ 4742: [Usaco2016 Dec]Team Building
4742: [Usaco2016 Dec]Team Building Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 21 Solved: 16[Su ...
- 【bzoj4580】[Usaco2016 Open]248 区间dp
题目描述 Bessie likes downloading games to play on her cell phone, even though she does find the small t ...
- bzoj 4506: [Usaco2016 Jan]Fort Moo
4506: [Usaco2016 Jan]Fort Moo Description Bessie is building a fort with her friend Elsie. Like any ...
- bzoj 4412: [Usaco2016 Feb]Circular Barn
4412: [Usaco2016 Feb]Circular Barn Description 有一个N个点的环,相邻两个点距离是1.点顺时针标号为1..N.每一个点有ci头牛,保证∑ci=N.每头牛都 ...
- BZOJ4580: [Usaco2016 Open]248
n<=248个数字,可以进行这样的操作:将相邻两个相同的数字合并成这个数字+1,求最大能合成多少. f(i,j)--区间i到j能合成的最大值,f(i,j)=max(f(i,k)+1),f(i,k ...
随机推荐
- .net4.0及Silverlight_Tools for vs2008sp1安装失败解决办法
安装.net framework 4.0失败,出现HRESULT 0xc8000222错误代码 1.开始-运行-输入cmd,运行命令 net stop WuAuServ 2.开始-运行-输入 ...
- ecshop目录结构
ECShop 最新程序 的结构图及各文件相应功能介绍ECShop文件结构目录┣ activity.php 活动列表┣ affiche.php 广告处理文件┣ affiliate.php 生成商品列表┣ ...
- thikphp创建共享数据config.php
要求:前台,后台:只需要配置一个config.php 其他文件共享 默认配置是 Index/Conf/config.php Admin/Conf/config.php 代码: return array ...
- yourphp读取分类名称{$Categorys[$r[catid]]['catname']}
页面代码: product_list.html 提供分类的id,找出分类的名称 {$Categorys[$r[catid]]['catname']}
- Robot Framework--06 用户关键字User Keyword
转自:http://blog.csdn.net/tulituqi/article/details/7906130 在我们做自动化案例的时候,用的最多的主要是用户关键字.说到关键字,大体上可以分为测试库 ...
- 网络广告术语CPC、CPM和CTR的含义和关系
1. CPC(Cost-per-click):对于广告主来说,就是每次点击(广告)的(付给网站主的)成本:对于媒体(或网站主)来说,就是用户每次点击(广告)(向广告主收取)的费用.可以用公 ...
- SSL、OPENSSL、SSH、OPENSSH
SSL(Secure Sockets Layer 安全套接层),及其继任者传输层安全(Transport Layer Security,TLS)是为网络通信提供安全及数据完整性的一种安全协议.TLS与 ...
- “mybatis 中使用foreach 传
为了帮助网友解决“mybatis 中使用foreach 传”相关的问题,中国学网通过互联网对“mybatis 中使用foreach 传”相关的解决方案进行了整理,用户详细问题包括:mybatismap ...
- Markdown语言详解
相信大家在github上面分享了不少的项目和Demo,每次创建新项目的时候,使用的都是默认的README.md文件,也不曾对这个文件有过什么了解.但是在看到别人写的项目的README.md里面竟然有图 ...
- Source Insight 基本使用(2)-修改Source Insight 快捷键
1. 首先,打开source insight主界面. 2. 选择"options->key assignments",进入快捷键设置界面. 3. 此时,可以看到快捷键设置对话 ...