洛谷 P3146 [USACO16OPEN]248
题目描述
Bessie likes downloading games to play on her cell phone, even though she doesfind the small touch screen rather cumbersome to use with her large hooves.
She is particularly intrigued by the current game she is playing.The game starts with a sequence of NN positive integers (2 \leq N\leq 2482≤N≤248), each in the range 1 \ldots 401…40. In one move, Bessie cantake two adjacent numbers with equal values and replace them a singlenumber of value one greater (e.g., she might replace two adjacent 7swith an 8). The goal is to maximize the value of the largest numberpresent in the sequence at the end of the game. Please help Bessiescore as highly as possible!
给定一个1*n的地图,在里面玩2048,每次可以合并相邻两个,问最大能合出多少
输入输出格式
输入格式:
The first line of input contains NN, and the next NN lines give the sequence
of NN numbers at the start of the game.
输出格式:
Please output the largest integer Bessie can generate.
输入输出样例
4
1
1
1
2
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.
思路:区间DP。f[i][j]表示区间i-j之间的最大值。
吐槽:加强版戳这里
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 300
using namespace std;
int n,ans;
int f[MAXN][MAXN];
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&f[i][i]);
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]);
}
cout<<ans;
}
洛谷 P3146 [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 题解 第一道自己码出的区间DP快庆祝一哈 2048 每次可以合并任意相邻的两个数字,得到的不是翻倍而是+1 dp[L][R] 区间 L~R 合并结果 然后 ...
- 洛谷 P3146 248 题解
https://www.luogu.org/problemnew/show/P3146 区间dp,这次设计的状态和一般的有一定的差异. 这次我们定义$dp[i][j]$表示$[i,j]$的可以合并出来 ...
- 又一道区间DP的题 -- P3146 [USACO16OPEN]248
https://www.luogu.org/problemnew/show/P3146 一道区间dp的题,以区间长度为阶段; 但由于要处理相邻的问题,就变得有点麻烦; 最开始想了一个我知道有漏洞的方程 ...
- 洛谷 P3143 [USACO16OPEN]钻石收藏家Diamond Collector 解题报告
P3143 [USACO16OPEN]钻石收藏家Diamond Collector 题目描述 Bessie the cow, always a fan of shiny objects, has ta ...
- 洛谷 P3143 [USACO16OPEN]钻石收藏家Diamond Collector 题解
P3143 [USACO16OPEN]钻石收藏家Diamond Collector 题目描述 Bessie the cow, always a fan of shiny objects, has ta ...
- P3146 [USACO16OPEN]248 & P3147 [USACO16OPEN]262144
注:两道题目题意是一样的,但是数据范围不同,一个为弱化版,另一个为强化版. P3146传送门(弱化版) 思路: 区间动规,设 f [ i ][ j ] 表示在区间 i ~ j 中获得的最大值,与普通区 ...
- 洛谷P3144 [USACO16OPEN]关闭农场Closing the Farm_Silver
题目描述 Farmer John and his cows are planning to leave town for a long vacation, and so FJ wants to tem ...
- 洛谷 P3144 [USACO16OPEN]关闭农场Closing the Farm_Silver
传送门 题目大意: n个谷仓 ,每次关闭一个谷仓,问剩下没被关闭的谷仓是 否联通. 题解:并查集+倒序处理 代码: #include<iostream> #include<cstdi ...
随机推荐
- BZOJ 5180 [Baltic2016]Cities(斯坦纳树)
斯坦纳树的板子题. 斯坦纳树问题是组合优化问题,与最小生成树相似,是最短网络的一种. 最小生成树是在给定的点集和边中寻求最短网络使所有点连通. 而最小斯坦纳树允许在给定点外增加额外的点,使生成的最短网 ...
- 中国剩余定理(excrt) 模板
excrt板子题 #include <cmath> #include <cstdio> #include <cstring> #include <algori ...
- [读书笔记] Python数据分析 (四) 数组和矢量计算
Numpy:高性能计算和数学分析的基础包 ndarray, 一个具有矢量算术运算和复杂广播能力的快速且节省空间的多维数组 用于对数组数据进行快速运算的标准数学函数 用于读写磁盘数据的工具和用于操作内存 ...
- leetcode小题解析
描述Given an array of integers, return indices of the two numbers such that they add up to a specific ...
- 如何成为资深的python专家
相信很多人有这种感受,python很简单,几天就学会了:做了一段时间就觉得python没什么好玩的,就这样. 一种语言有火这么久,必有它存在的道理. 第一.我们要相信她,她就像你的新女朋友一样,她会给 ...
- linux 文件的权限说明
1.开头 d:表示问文件夹 ( directory ) -:表示普通二进制文件 ( 压缩包.文件 等等 ) l:表示软连接文件 ( link 硬链接或软链接 ) 2.权限 ( 3 个为一组 ) r:读 ...
- ZOJ 3688
做出这题,小有成就感 本来已打算要用那个禁位的排列公式,可是,问题在于,每个阶乘前的系数r的求法是一个难点. 随便翻了翻那本美国教材<组合数学>,在容斥原理一章的习题里竟有一道类似,虽然并 ...
- Oracle_角色_权限具体说明
一.Oracle内置角色connect与resource的权限 grant connect,resource to user; CONNECT角色: --是授予终于用户的典型权利,最主要的 ALT ...
- Linux防火墙限制指定port仅仅能由指定IP訪问
须要对redis的端口做限制,仅仅能让公司内指定IP的机器訪问 -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A ...
- node--20 moogose demo2
db.js /** * Created by Danny on 2015/9/28 16:44. */ //引包 var mongoose = require('mongoose'); //创建数据库 ...