博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
洛谷P3146 [USACO16OPEN]248
阅读量:7070 次
发布时间:2019-06-28

本文共 1809 字,大约阅读时间需要 6 分钟。

 

题目描述

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 positive integers (), each in the range . 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 , and the next lines give the sequence

of numbers at the start of the game.

输出格式:

Please output the largest integer Bessie can generate.

输入输出样例

输入样例#1:
41112
输出样例#1:
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.

 

思路简直神奇

动规/递推

设f[i][j]为在[j]位置的数字[i]与它后面的数合并后的位置。

数最大为40,那么最大能合成到大概50+

1 #include
2 #include
3 #include
4 #include
5 #include
6 #define LL long long 7 using namespace std; 8 const int mxn=300; 9 int f[101][mxn];10 int n;11 int main(){12 scanf("%d",&n);13 int i,j;14 int a;15 for(i=1;i<=n;i++){16 scanf("%d",&a);17 f[a][i]=i+1;18 }19 int ans=0;20 for(i=1;i<=60;i++){21 for(j=1;j<=n;j++){22 if(!f[i][j])f[i][j]=f[i-1][f[i-1][j]];23 if(f[i][j])ans=i;24 }25 }26 cout<
<

 

转载于:https://www.cnblogs.com/SilverNebula/p/5927770.html

你可能感兴趣的文章
再次简单明了总结flex布局,一看就懂...
查看>>
一步步学会用docker部署应用(nodejs版)
查看>>
无root权限新建git仓库进行多人协同工作
查看>>
【跃迁之路】【687天】程序员高效学习方法论探索系列(实验阶段444-2019.1.6)...
查看>>
假装用某米赛尔号的角度看Python面向对象编程
查看>>
RGBA和OPACITY的区别&DISPLAY和VISIBILITY的区别
查看>>
膨胀的template class成员函数
查看>>
【leetcode】102. Binary Tree Level Order Traversal 水平遍历二叉树
查看>>
java中的内存模型
查看>>
Vue 初始化性能优化
查看>>
[LeetCode] Sudoku Solver [Backtracking]
查看>>
js函数调用模式和常用的几个方法
查看>>
zookeeper:集群中实例的数量
查看>>
基于redis实现的锁(用于控制nodejs的并发)
查看>>
js手札--关于AMD的简单分析
查看>>
Elixir Ranch: 一个用于处理套接字的网络库
查看>>
JMS规范及相关实现
查看>>
衡量企业应用数据库性能的6大指标
查看>>
ng的缓存模板的用法
查看>>
Vimium 快捷键指南
查看>>