Problem Description
MZL is a mysterious mathematician, and he proposed a mysterious function at his young age.
Stilwell is very confused about this function, and he need your help.
First of all, given n positive
integers Ai and Ai≥Ai+1.
Then, generate n positive
integers Bi

Bi=∑j=inAj

Define f(i,j) for i,j∈Z

f(i,j)=⎧⎩⎨⎪⎪⎪⎪⎪⎪0min(f(i−1,j+1),f(i,⌈j2⌉)+Bi)1011037(i,j)=(1,1)i,j∈[1,n], (i,j)≠(1,1)otherwise

Find f(n,1).

 
Input
The first line of the input contains a single number T,
the number of test cases.
For each test case, the first line contains a positive integer n,
and the next line contains n positive
integers Ai.
T≤100, 1≤n≤105, ∑n≤106, 1≤Ai≤104.
 
Output
For each test case, output f(n,1) in
a line.
 
Sample Input
3
3
1 1 1
5
28 26 25 24 1
10
996 901 413 331 259 241 226 209 139 49
 
Sample Output
5
233
11037

//完全没看出来是个huffman - -!

#include <iostream>
#include <cstdio>
#include<algorithm>
#include<cstring>
#include<functional>
#include<queue>
typedef long long ll;
using namespace std; int main()
{
int T;
int n,a;
priority_queue<ll, vector<ll>, greater<ll> >q;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
while(!q.empty())
{
q.pop();
}
for(int i=1; i<=n; i++)
{
scanf("%d",&a);
q.push(a);
}
ll sum = 0;
while(!q.empty())
{
ll x = q.top();
q.pop();
if(q.empty())
{
continue;
}
ll y = q.top();
q.pop();
ll tmp= x + y;
sum+=tmp;
q.push(tmp);
}
printf("%I64d\n",sum);
}
return 0;
}

  

2015 多校联赛 ——HDU5350(huffman)的更多相关文章

  1. 2015 多校联赛 ——HDU5334(构造)

    Virtual Participation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  2. 2015 多校联赛 ——HDU5302(构造)

    Connect the Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  3. 2015 多校联赛 ——HDU5294(最短路,最小切割)

    Tricks Device Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  4. 2015 多校联赛 ——HDU5325(DFS)

    Crazy Bobo Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Tota ...

  5. 2015 多校联赛 ——HDU5316(线段树)

    Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...

  6. 2015 多校联赛 ——HDU5323(搜索)

    Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  7. 2015 多校联赛 ——HDU5319(模拟)

    Painter Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Su ...

  8. 2015 多校联赛 ——HDU5301(技巧)

    Your current task is to make a ground plan for a residential building located in HZXJHS. So you must ...

  9. 2015 多校联赛 ——HDU5303(贪心)

    Delicious Apples Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Other ...

随机推荐

  1. C语言--第14.15周作业

    一. 7-3 将数组中的数逆序存放 1.代码 #include 2<stdio.h> int main() { int a[10]; int i, n, s; scanf("%d ...

  2. 团队作业7——第二次项目冲刺(Beta版本12.05-12.07)

    1.当天站立式会议照片 本次会议内容:1:每个人汇报自己完成的工作.2:组长分配各自要完成的任务. 2.每个人的工作 黄进勇:项目整合,后台代码. 李勇:前台界面优化. 何忠鹏:数据库模块. 郑希彬: ...

  3. HTTP协议以及HTTP2.0/1.1/1.0区别

    HTTP协议以及HTTP2.0/1.1/1.0区别 一.简介 摘自百度百科: 超文本传输协议(HTTP,HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议.所 ...

  4. Linux下关闭Tomcat残留线程

    ps -ef | grep tomcat kill -9 {pid}

  5. 【译】Gradle 的依赖关系处理不当,可能导致你编译异常

    文章 | Ashesh Bharadwaj 翻译 | 承香墨影 授权 承香墨影 翻译.编辑并发布 在 Android Studio 中,Gradle 构建过程对于开发者来说,很大程度上是抽象的.作为一 ...

  6. Ubuntu安装使用latex

    TeX Live is a TeX distribution to get up and running with the TeX document production system. To ins ...

  7. MySQL/MariaDB中游标的使用

    本文目录:1.游标说明2.使用游标3.游标使用示例 1.游标说明 游标,有些地方也称为光标.它的作用是在一个结果集中逐条逐条地获取记录行并操作它们. 例如: 其中select是游标所操作的结果集,游标 ...

  8. 帧动画的创建方式 - 纯Java代码方式

    废话不多说,先看东西 帧动画的创建方式主要以下2种: * 用xml创建动画: * 纯Java代码创建动画:   本文内容主要关注 纯java代码创建帧动画 的方式: 用xml创建帧动画:http:// ...

  9. 使用cxf创建webservice 出现timeOut的问题,设置spring超时时间

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  10. node.js的安装的配置

    一.Node.js 安装配置 Node.js 提供在Windows和Linux上安装 1.  Window 上安装Node.js 64 位安装包下载地址 : https://nodejs.org/di ...