zoukankan      html  css  js  c++  java
  • 洛谷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 }
  • 相关阅读:
    Spring-boot内置的程序管理监控工具-Actuator
    分表工具类(根据唯一字符串)
    ES设计及规范
    测试单元Junit一直进不去@test方法解决方案
    MAC OS怎样将普通成员升级为管理员
    elasticSearch小结
    Mysql 查询条件中字符串尾部有空格也能匹配上的问题
    gitlab进行meger代码回滚
    ES与关系型数据库的通俗比较
    kafka的生产者配置以及发送信息的三种方式
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/5927770.html
Copyright © 2011-2022 走看看