D:Lift Problems

On the ground floor (floor zero) of a large university building a number of students are wait- ing for a lift. Normally, the lift stops at every floor where one or more students need to get out, but that is annoying for the students who want to get out on a higher floor. Alternatively, the lift could skip some floors, but that is annoying for the students who wanted to get out on one of those floors.

Specifically, a student will be annoyed on every floor where the lift stops, if the lift has not yet reached the floor on which he or she wants to get out. If the lift skips the floor on which a student wants to get out, he or she will be annoyed on that floor and every higher floor, up to (and excluding) the floor where the lift makes its next stop and the student can finally get out to start walking back down the stairs to his or her destination.For example, if a student wants to get out on the fifth floor, while the lift stops at the second, seventh and tenth floor, the student will be annoyed on floors two, five and six. In total, this student will thus be annoyed on three floors.

Upon entering the lift, every student presses the button corresponding to the floor he or she wants to go to, even if it was already pressed by someone else. The CPU controlling the lift thus gets to know exactly how many students want to get out on every floor.

You are charged with programming the CPU to decide on which floors to stop. The goal is to minimize the total amount of lift anger: that is, the number of floors on which every student is annoyed, added together for all students.

You may ignore all the people who may (want to) enter the lift at any higher floor. The lift has to operate in such a way that every student waiting at the ground floor can reach the floor she or he wants to go to by either getting out at that floor or by walking down the stairs.

输入格式

On the first line one positive number: the number of test cases, at most 100. After that per test case:

  • one line with a single integer n (1≤n≤1500): the number of floors of the building, excluding the ground floor.
  • one line with n space-separated integers si​ (0≤si≤15000): for each floor i, the number of students si that want to get out.

输出格式

Per test case:

  • one line with a single integer: the smallest possible total amount of lift anger.

样例输入

3
5
0 3 0 0 7
5
0 0 3 0 7
10
3 1 4 1 5 9 2 6 5 3

样例输出

7
6
67
枚举法,如果当前电梯停的话,则此时的愤怒值为上次电梯停时到现在中间所有人的持续愤怒和当前到顶层所有人的一次愤怒(动态规划)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int t,n,a[],ans[];
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
a[i]+=a[i-];
}
ans[]=;
for(int i=;i<=n;i++)
{
ans[i]=INF;
for(int j=i-;j>=;j--)
{
ans[i]=min(ans[i],ans[j]+a[n]-a[i]);
ans[j]+=a[i]-a[j];
}
// printf("%d ",ans[i]);
} printf("%d\n",ans[n]);
}
return ;
}

BAPC 2014 Preliminary(第一场)的更多相关文章

  1. 计蒜客 28206.Runway Planning (BAPC 2014 Preliminary ACM-ICPC Asia Training League 暑假第一阶段第一场 F)

    F. Runway Planning 传送门 题意简直就是有毒,中间bb一堆都是没用的,主要的意思就是度数大于180度的就先减去180度,然后除以10,四舍五入的值就是答案.如果最后结果是0就输出18 ...

  2. 计蒜客 28202. Failing Components-最短路(Dijkstra) (BAPC 2014 Preliminary ACM-ICPC Asia Training League 暑假第一阶段第一场 B)

    B. Failing Components 传送门 题意就是单向图,从起点开始找最短路,然后统计一下个数就可以.方向是从b到a,权值为s. 直接最短路跑迪杰斯特拉,一开始用数组版的没过,换了一个队列版 ...

  3. 计蒜客 28201.Choosing Ice Cream-gcd (BAPC 2014 Preliminary ACM-ICPC Asia Training League 暑假第一阶段第一场 A)

    开始水一波博客 题目链接: A. Choosing Ice Cream 传送门 题意就是n个冰淇淋,骰子有k个面,问你是否能在公平的概率下转几次骰子能确定买哪个冰淇淋. 举个例子,假设我只有一个冰淇淋 ...

  4. BAPC 2014 Preliminary

    // 题目链接: https://nanti.jisuanke.com/t/282041 //动态规划,重复利用子问题的最优,来求解当前最优问题 #include <iostream> # ...

  5. 校省选赛第一场C题解Practice

    比赛时间只有两个小时,我没有选做这题,因为当时看样例也看不懂,比较烦恼. 后来发现,该题对输入输出要求很低.远远没有昨天我在做的A题的麻烦,赛后认真看了一下就明白了,写了一下,一次就AC了,没问题,真 ...

  6. 校省选赛第一场A题Cinema题解

    今天是学校省选的第一场比赛,0战绩收工,死死啃着A题来做,偏偏一直WA在TES1. 赛后,才发现,原来要freopen("input.txt","r",stdi ...

  7. 数据结构《21》----2014 WAP 第一个问题----Immutable queue

    2014 WAP第一个问题----实现一个不可改变的队列: 看似非常easy.. 其实,不同的版本号之间的效率差距可能是巨大的.. 甚至难以想象. . 使用前STL图书馆queue我们进行了比较.大差 ...

  8. 计蒜之道 初赛第一场B 阿里天池的新任务(简单)

    阿里“天池”竞赛平台近日推出了一个新的挑战任务:对于给定的一串 DNA 碱基序列 tt,判断它在另一个根据规则生成的 DNA 碱基序列 ss 中出现了多少次. 首先,定义一个序列 ww: \displ ...

  9. hdu 5288||2015多校联合第一场1001题

    pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...

随机推荐

  1. 【Linux驱动】TQ2440 DM9000E网卡驱动移植(Linux-2.6.30.4)

    花了一天的时间研究了一下Linux-2.6.30.4版本号内核下关于TQ2440 DM9000E的网卡驱动移植.总结一下自己的收获. 事实上.在Linux-2.6.30.4版本号内核下有关于网卡驱动, ...

  2. m_Orchestrate learning system---五、学的越多,做的越快

    m_Orchestrate learning system---五.学的越多,做的越快 一.总结 一句话总结: 1.上传的图像文件用input('post.')方法取不到是为什么? 图片不来就这样取不 ...

  3. Redis-3-string类型

    Redis-3-string类型 标签(空格分隔): redis set key value [ex 秒数] / [px 毫秒数] [nx] /[xx] mset key value key valu ...

  4. 15-11-23:system指令

    CMD命令:开始->运行->键入cmd或command(在命令行里可以看到系统版本.文件系统版本) 1. appwiz.cpl:程序和功能 2. calc:启动计算器 3. certmgr ...

  5. POJ 3268 Dijkstra+priority_queue或SPFA

    思路:正向建边,一遍Dijkstra,反向建边,再一遍Dijkstra.ans加在一起输出最大值. (SPFA也行--) // by SiriusRen #include <queue> ...

  6. ETL工具的功能和kettle如何来提供这些功能

    不多说,直接上干货! 大家会有一个疑惑,本系列博客是Kettle,那怎么扯上ETL呢? Kettle是一款国外开源的ETL工具,纯java编写,可以在Window.Linux.Unix上运行. 说白了 ...

  7. 编译Speex生成so库文件(android-speex)

    项目中需要用音频格式转换,之前使用VoAacEncoder,部分手机总是莫名崩溃,所以决定不再使用VoAacEncoder,换做Speex来完成格式转换,但是没有找到Speex的库文件,网上介绍的都是 ...

  8. express + multer 文件上传入门

    写在前面的 在web开发中,我们经常会遇到图片上传的功能,接下来我们就在express4.15.0框架中利用multer1.3.0模块来实现图片上传 开始敲代码 首先利用express-generat ...

  9. jQuery基本操作以及与js的一些比较

    jQuery和js主要区别在DOM操作 用jQuery必须先引进jQuery.js文件 js和jQuery写在哪: 1.标签里面 常用就是方法调用 2.写在script标签里面 3.js文件 dom操 ...

  10. P1017 进制转换 (负进制转换)

    和平常的转化差不多 加多一步 如果余数 < 0, 那么余数减去除数(此时除数是负),商数加1 #include<cstdio> #define _for(i, a, b) for(i ...