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 }
  • 相关阅读:
    mybatis强化(二)Parameters和Result
    operator new 和 new operator
    hdu 1007 Quoit Design 分治求最近点对
    实现一个简单的shared_ptr
    bzoj 3224: Tyvj 1728 普通平衡树 替罪羊树
    bzoj 2648 SJY摆棋子 kd树
    hdu 2966 In case of failure k-d树
    codeforces 713D D. Animals and Puzzle 二分+二维rmq
    bzoj 1188 : [HNOI2007]分裂游戏 sg函数
    bzoj 1912 : [Apio2010]patrol 巡逻 树的直径
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/5927770.html
Copyright © 2011-2022 走看看