zoukankan      html  css  js  c++  java
  • 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];

    以下代码:

    #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
    ",m);
      return 0;
    }
    View Code
  • 相关阅读:
    win10安装vue
    通过docker安装rabbitmq
    python定时访问主机进程信息并反馈到远程服务器
    win10配置Apache+部署静态html页面
    HTTP协议—HTTP报文格式详解
    python脚本编写(纯干货)
    linux/CentOS的安装(萌新版)
    gradle中调用ant.unzip对zip包解压缩
    通过gradle运行测试脚本
    使用rest-assured测试rest service, 遇到“415 Unsupported Media Type”
  • 原文地址:https://www.cnblogs.com/Jessie-/p/9845740.html
Copyright © 2011-2022 走看看