dti是什么意思_happygame是哪个应用

dti是什么意思_happygame是哪个应用2018.10.24-dtij-2636-262144(game)

大家好,又见面了,我是你们的朋友全栈君。

题目描述:

Bessie likes downloading games to play on her cell phone, even though she does find 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 N positive integers (2≤N≤262,144), each in the range 1…40. In one move, Bessie can take two adjacent numbers with equal values and replace them a single number of value one greater (e.g., she might replace two adjacent 7s with an 8). The goal is to maximize the value of the largest number present in the sequence at the end of the game. Please help Bessie score as highly as possible!

给定n个1到40之间的数,每次可以将两个相邻的相等的数替换成一个比它们大1的数(比如,相邻的7 7可以替换成8),你需要让最后剩下的数中的最大数尽量大

输入:

The first line of input contains N, and the next N lines give the sequence of N numbers at the start of the game.

输出:

Please output the largest integer Bessie can generate.

算法标签:DP(很常见的一个类似倍增的dp)

思路:

其实合并的过程很类似一个倍增的过程,且仔细分析发现数字的大小最大值58大概,所以就用

当f[i][j]!=0&&f[f[i][j]+1]!=0时可以有转移f[i][j+1]=f[f[i][j]+1][j];

以下代码:

dti是什么意思_happygame是哪个应用
dti是什么意思_happygame是哪个应用

#include<bits/stdc++.h>
#define il inline
#define _(d) while(d(isdigit(ch=getchar())))
using namespace std;
const int N=262150;int n,f[N][70],m;
il int read(){
    
    int x,f=1;char ch;_(!)ch=='-'?f=-1:f;x=ch^48;_()x=(x<<1)+(x<<3)+(ch^48);return f*x;}
int main()
{
    n=read();for(int i=1;i<=n;i++){
    
    int x=read();f[i][x]=i;m=max(m,x);}
    for(int i=1;i<=m;i++)for(int j=1;j<=n;j++)
        if(f[j][i]!=0&&f[f[j][i]+1][i]!=0){
            f[j][i+1]=f[f[j][i]+1][i];if(i+1>m)m=i+1;
        }printf("%d\n",m);
  return 0;
}

View Code

 

转载于:https://www.cnblogs.com/Jessie-/p/9845740.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/107236.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号