[USACO16OPEN]248
分析:
一个裸的区间dp,我们只需要注意合并的时候并不像2048那样加倍,每次都加1就好了
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = ; inline int read(){
int f = , x = ;
char ch = getchar();
while(ch > '' || ch < '') {if(ch == '-') f = -; ch = getchar();}
while(ch >= '' && ch <= ''){x = (x << ) + (x << ) + ch - ''; ch = getchar();}
return x * f;
} int n,m;
int f[maxn][maxn],ans; int main(){
n = read();
for(int i=;i<=n;i++) f[i][i] = read() , ans = max(ans , f[i][i]);
for(int i=n;i>=;i--)
for(int j=i+;j<=n;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",ans);
return ;
}
[USACO16OPEN]248的更多相关文章
- 洛谷P3146 [USACO16OPEN]248
P3146 [USACO16OPEN]248 题目描述 Bessie likes downloading games to play on her cell phone, even though sh ...
- 洛谷 P3146 [USACO16OPEN]248
P3146 [USACO16OPEN]248 题目描述 Bessie likes downloading games to play on her cell phone, even though sh ...
- P3146 [USACO16OPEN]248
P3146 [USACO16OPEN]248 题解 第一道自己码出的区间DP快庆祝一哈 2048 每次可以合并任意相邻的两个数字,得到的不是翻倍而是+1 dp[L][R] 区间 L~R 合并结果 然后 ...
- [USACO16OPEN]248 G——区间dp
[USACO16OPEN]248 G 题目描述 Bessie likes downloading games to play on her cell phone, even though she do ...
- 「区间DP」「洛谷PP3146 」[USACO16OPEN]248 G
[USACO16OPEN]248 G 题目: 题目描述 Bessie likes downloading games to play on her cell phone, even though sh ...
- 又一道区间DP的题 -- P3146 [USACO16OPEN]248
https://www.luogu.org/problemnew/show/P3146 一道区间dp的题,以区间长度为阶段; 但由于要处理相邻的问题,就变得有点麻烦; 最开始想了一个我知道有漏洞的方程 ...
- 【动态规划DP】[USACO16OPEN]248
题目描述 Bessie likes downloading games to play on her cell phone, even though she doesfind the small to ...
- P3146 [USACO16OPEN]248 & P3147 [USACO16OPEN]262144
注:两道题目题意是一样的,但是数据范围不同,一个为弱化版,另一个为强化版. P3146传送门(弱化版) 思路: 区间动规,设 f [ i ][ j ] 表示在区间 i ~ j 中获得的最大值,与普通区 ...
- P3146 [USACO16OPEN]248 (区间DP)
题目描述 给定一个1*n的地图,在里面玩2048,每次可以合并相邻两个(数值范围1-40),问最大能合出多少.注意合并后的数值并非加倍而是+1,例如2与2合并后的数值为3. 这道题的思路: 状态: ...
随机推荐
- SSH框架搭建问题总结
1.eclipse中tomcat配置是否正确?能否在网页中访问的到? 如何在eclipse中配置tomcat就不说了,我们看下问题,在网页上访问tomcat的地址,为什么出现404错误呢? 解决办法: ...
- NFS服务端+客户端配置
一.Server端配置 1.下载rpcbind和nfs #yum install -y rpcbind nfs-utils 2.创建共享文件并授权 创建共享文件夹 #mkdir /server-nfs ...
- python学习(20) 网络编程
原文链接:http://www.limerence2017.com/2018/01/02/python20/ python 网络编程和基本的C语言编程一样,效率不是很高,如果为了封装通信库建议采用C/ ...
- HAOI2018游记
前言 很懒. 太懒了. 不仅懒得写题..连游记都懒得写.. 花点时间填一下坑吧..不过话说我去年的NOI/APIO/CTSC游记也没写.. 省选前 板子好像一早就打完了,没什么可干的. 也不愿意开新题 ...
- No module named 'urllib.request'; 'urllib' is not a package
想学爬虫urllib的设置代理服务器,于是把之前跳过没学的urllib捡起来,敲了段简单的代码,如下 import urllib.request url = "http://www.baid ...
- 设置CMD默认路径
用CMD每一次都得切换路径,很麻烦. 所以,需要设置一下CMD默认路径: 1.打开注册表编辑器(WIN+R打开运行.输入regedit) 2.定位到: “HKEY_CURRENT_USER\Softw ...
- 「Vue」程序式路由导航用法
1.button发起点击请求<mt-button type='primary' size='large' plain @click="topdcmt(id)">商品评论 ...
- P2657 [SCOI2009]windy数
P2657 [SCOI2009]windy数 题目描述 windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道, 在A和B之间,包括A和B ...
- windows下静态编译pthread
1. Building the library as a statically linkable library-------------------------------------------- ...
- 2017 国庆湖南 Day1
卡特兰数 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ] ...