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 }
  • 相关阅读:
    【面试突击】-RabbitMQ常见面试题(一)
    并发艺术--java并发编程基础
    并发艺术--java内存模型
    并发艺术--java并发机制的底层实现原理
    并发艺术--并发编程挑战
    Spring Boot 项目中的 parent
    封装关于金额计算的double工具类
    日期和字符串类型相互转换工具类
    统一封装json返回结果
    Hibernate-validator数据验证
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/5927770.html
Copyright © 2011-2022 走看看