[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. 这道题的思路: 状态: ...
随机推荐
- python之旅:三元表达式、列表推导式、生成器表达式、函数递归、匿名函数、内置函数
三元表达式 #以下是比较大小,并返回值 def max2(x,y): if x > y: return x else: return y res=max2(10,11) print(res) # ...
- Facenet Triplet Loss
Triplet Loss 在人脸识别中,Triplet loss被用来进行人脸嵌入的训练.如果你对triplet loss很陌生,可以看一下吴恩达关于这一块的课程.Triplet loss实现起来并不 ...
- Python 爬虫入门(一)
毕设是做爬虫相关的,本来想的是用java写,也写了几个爬虫,其中一个是爬网易云音乐的用户信息,爬了大概100多万,效果不是太满意.之前听说Python这方面比较强,就想用Python试试,之前也没用过 ...
- python中的文件操作
文件操作时,有'r','w','a'不同的操作类型,其中'r'只能读文件,seek(),tell()函数定位读的起始地方.'w'会清空文件内容然后写文件,seek(),tell()函数定位写的起始地方 ...
- spring中的控制反转
为什么使用spring框架,控制反转是它的重要优势之一. 传统的程序设计中,某个对象需要被调用时(比如mvc模式中controller调用service),需要调用者自己创建被调用对象. 而在spri ...
- servlet拦截器
servlet拦截未登录的用户请求 java代码: package com.gavin.filter; import java.io.IOException; import javax.servlet ...
- oracle进阶之分析函数
本博客是自己在学习和工作途中的积累与总结,纯属经验之谈,仅供自己参考,也欢迎大家转载,转载时请注明出处. http://www.cnblogs.com/king-xg/p/6797119.html 分 ...
- Android studio 使用flutter插件 运行第一个flutter项目 报错 Warning: License for package Android SDK Build-Tools 28.0.3 not accepted.
在Android studio中新建了flutter项目.运行报错licence not accepted. Warning: License for package Android SDK Buil ...
- bzoj千题计划171:bzoj2456: mode
http://www.lydsy.com/JudgeOnline/problem.php?id=2456 任意删除序列中两个不同的数,众数仍然是众数 不停的删,剩下的最后的数一定是众数 具体实现: 记 ...
- bzoj千题计划166:bzoj2179: FFT快速傅立叶
http://www.lydsy.com/JudgeOnline/problem.php?id=2179 FFT做高精乘 #include<cmath> #include<cstdi ...