洛谷P3146 [USACO16OPEN]248

Posted SilverNebula

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了洛谷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 技术分享 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:
4
1
1
1
2
输出样例#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<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cmath>
 5 #include<queue>
 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<<ans<<endl;
27     return 0;
28 }

 

以上是关于洛谷P3146 [USACO16OPEN]248的主要内容,如果未能解决你的问题,请参考以下文章

P3146 [USACO16OPEN]248

[DP 区间 转移限制] P3146 [USACO16OPEN]248 G

luogu P3146 [USACO16OPEN]248

P3146 [USACO16OPEN]248 G

luogu3146 [USACO16OPEN]248

USACO16OPEN 248