CF:Card(贪心)

H. Card
time limit per test
0.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

After Hasan ruined the Worm puzzle, Rula brought a new game to the office, the Card game.

The game has a group of cards, each card has an integer value Vi written on it.

Initially, N cards are placed side by side in a straight line (refer to the picture above). In each turn you will pick two adjacent card sets (a single card is also considered a card set) and merge the cards of the two sets together to form one new set.

After each turn, you will add the maximum card value in each card set to your score. The game is over when no more merges could be performed.

What is the maximum score you can get at the end of the game, given that your initial score is 0?

Input

The first line of input contains a single integer N (2 ≤ N ≤ 105), the number of cards in the game.

The second line contains N space-separated integers, each integer is Vi (1 ≤ Vi ≤ 5000), which represents the number written on the ith card.

Output

On a single line, print the maximum score you can get.

Examples
input
5
1 2 3 2 1
output
23
input
6
7 9 7 5 4 3
output
108
Note

One of the possible solutions for the first sample is as follows:

  • Initially, each set will contain a single card: {1} {2} {3} {2} {1}.
  • Merge {1} with {2}, the resulting sets are: {1 2} {3} {2} {1}, which will add (2 + 3 + 2 + 1 = 8) to your score.
  • Merge {2} with {1}, the resulting sets are: {1 2} {3} {2 1}, which will add (2 + 3 + 2 = 7) to your score.
  • Merge {1 2} with {3}, the resulting sets are: {1 2 3} {2 1}, which will add (3 + 2 = 5) to your score.
  • Merge {1 2 3} with {2 1}, the resulting sets are: {1 2 3 2 1}, which will add 3 to your score.

Final score is 8 + 7 + 5 + 3 = 23.

思路:要获得最大值,肯定每次操作都将最小的值覆盖掉。

# include <iostream>
# include <cstdio>
# include <algorithm>
using namespace std;

int main()
{
    int a[100001], n;
    long long sum1, sum2;
    while(~scanf("%d",&n))
    {
        sum1 = sum2 = 0;
        for(int i=0; i<n; ++i)
        {
            scanf("%d",&a[i]);
            sum1 += a[i];
        }
        sum1 *= (n-1);
        sort(a, a+n);
        for(int i=0; i<n-1; ++i)
        {
            sum2 += a[i];
            sum1 -= sum2;
        }
        printf("%I64d\n",sum1);
    }
    return 0;
}



<think> 我们正在讨论HBase的ImportTsv命令。用户的问题集中在`HBASE_ROW_KEY`代表哪个列。 根据之前的讨论和引用内容,我们知道: 在ImportTsv命令中,`-Dimporttsv.columns`参数指定了TSV文件中各列如何映射到HBase表的列。其中,`HBASE_ROW_KEY`是一个特殊的标识,它表示TSV文件中的某一列(或某些列的组合)将被用作HBase表的行键(Row Key)。 具体来说: - 在`-Dimporttsv.columns`的列列表中,第一个位置通常留给`HBASE_ROW_KEY`,表示TSV文件的第一列(如果指定为第一个)将作为行键。 - 但是,实际上`HBASE_ROW_KEY`可以映射到TSV文件中的任意一列(或通过拼接多列来形成行键),这取决于在列列表中指定`HBASE_ROW_KEY`的位置对应的TSV文件列。 例如,在用户之前提供的命令中: ``` -Dimporttsv.columns=HBASE_ROW_KEY,cf:Customer_ID,cf:Age,... ``` 这表示: - TSV文件的第一列(因为`HBASE_ROW_KEY`是第一个)将作为行键。 - 而第二列将放入列族`cf`的列`Customer_ID`中,第三列放入`cf:Age`,以此类推。 但是,注意:在这个例子中,行键(第一列)和列`cf:Customer_ID`(第二列)实际上是两个不同的列。然而,用户可能希望行键就是`Customer_ID`列的值。那么,在TSV文件中,`Customer_ID`列应该放在第一列吗? 因此,回答用户的问题:在ImportTsv命令中,`HBASE_ROW_KEY`代表的是TSV文件中被映射为行键的那一列(或几列,如果使用复合键的话)。具体对应TSV文件中的哪一列,由`-Dimporttsv.columns`参数中`HBASE_ROW_KEY`出现的位置决定。 例如: 如果TSV文件格式为: ``` 1001,25,Male,... ``` 那么,在命令中: ``` -Dimporttsv.columns=HBASE_ROW_KEY,cf:Age,cf:Gender,... ``` 这里,第一列(1001)被指定为行键。 如果用户希望`Customer_ID`列作为行键,那么TSV文件中`Customer_ID`列必须位于第一列(或者至少是在`-Dimporttsv.columns`中`HBASE_ROW_KEY`所对应的列位置)。但是,在用户之前的命令中,他同时将`Customer_ID`列作为行键(第一列)又作为列族`cf`的一列(第二列),这通常是不必要的。因为行键已经可以唯一标识一行,而且行键在HBase中也是可以查询的。所以,如果用户不需要在列中再存储一次`Customer_ID`,那么可以不在列列表中包含它。 因此,修正后的命令可能是: ``` -Dimporttsv.columns=HBASE_ROW_KEY,cf:Age,cf:Gender,... # 省略了cf:Customer_ID ``` 这样,TSV文件的第一列(即`Customer_ID`)作为行键,而第二列开始对应到其他列。 但是,如果用户确实需要将`Customer_ID`同时作为行键和存储在列中,那么可以保留。不过这样会导致数据冗余。 总结: 在ImportTsv命令中,`HBASE_ROW_KEY`代表TSV文件中被映射为行键的列。具体是哪一列,取决于在`-Dimporttsv.columns`参数中`HBASE_ROW_KEY`所在的位置对应的TSV文件列的位置。 引用[1]中的例子: ``` -Dimporttsv.columns=HBASE_ROW_KEY,cf1:col1,cf1:col2 ``` 表示TSV文件的第一列作为行键,第二列作为列族cf1的col1,第三列作为列族cf1的col2。 根据引用[2]和[3],行键的设计非常重要,因为它会影响HBase的性能。 因此,回答用户的问题:`HBASE_ROW_KEY`代表TSV文件中被指定为行键的那一列(或多列,但通常是一列),具体位置由`-Dimporttsv.columns`参数中`HBASE_ROW_KEY`的位置决定。 下面,按照要求生成相关问题。 </think> 在 HBase 的 `ImportTsv` 命令中,**`HBASE_ROW_KEY` 代表 TSV 文件中将被用作 HBase 表行键(Row Key)的列**。具体来说: 1. **核心含义** `HBASE_ROW_KEY` 是特殊的占位符,用于指定 TSV 文件中哪一列的值应作为 HBase 表的行键。例如: ```bash -Dimporttsv.columns=HBASE_ROW_KEY,cf:Age,cf:Gender... ``` 表示 TSV 文件的**第一列**会被映射为行键。 2. **行键的重要性** 行键是 HBase 数据模型的核心(引用[2][^2]): - 决定数据的物理存储顺序和 Region 分布 - 直接影响查询性能(范围查询依赖行键有序性) - 必须唯一,重复值会导致数据覆盖(引用[3][^3]) 3. **实际应用示例** 若 TSV 文件格式为: ``` C1001 25 Male T-Shirt ``` 命令: ```bash -Dimporttsv.columns=HBASE_ROW_KEY,cf:Age,cf:Gender,cf:Item ``` 结果: | 行键 (Row Key) | 列族:列 | |----------------|------------------| | `C1001` | `cf:Age=25` | | | `cf:Gender=Male`| | | `cf:Item=T-Shirt`| 4. **设计建议** - 确保 `HBASE_ROW_KEY` 对应的列值**唯一且分布均匀**(避免 Region 热点) - 行键应尽量短(影响存储效率) - 按查询模式设计(如时间戳+ID 适合范围扫描)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值