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. CDOJ 876 爱管闲事 DP

    爱管闲事 春希非常爱管闲事,他每天都会抽空帮助一些同学,由于春希非常死板,出于公平性,春希不会先帮助后来找他的同学. 现在有n个同学需要他的帮助,虽然他很想一天之类帮助所有人,但毕竟精力有限,于是他决 ...

  2. NOIP2017提高组模拟赛4 (总结)

    NOIP2017提高组模拟赛4 (总结) 第一题 约数 设K是一个正整数,设X是K的约数,且X不等于1也不等于K. 加了X后,K的值就变大了,你可以重复上面的步骤.例如K= 4,我们可以用上面的规则产 ...

  3. CentOS7系统安装完MySQL后启动MySQL提示无服务

    重新安装MariaDB数据库即可解决,MySQL所有命令可通用 MariaDB MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,开发这个分支的原因之一是:甲骨文公司收购了My ...

  4. Linux基础02

    ** Linux基本操作常用命令(二) ** 用户名与主机名 当你进入Linux终端时,你会看到如下样式的图片:     其中[z@z01]方括号内的z表示当前系统登录操作的用户名,@后的z01表示当 ...

  5. Spannable对textview首行缩进的设置

    1.创建Spannable对象 SpannableString contentSpan = new SpannableString(data.getBusinessTitle()); 2.设置文本缩进 ...

  6. PCL例程调试错误之缺少flann-config.cmake

    编译环境和PCL版本为:win7-x64 + MSVC2013 + PCL1.8.0-win32-MSVC2013. 调试PCL官网例程Cluster Recognition and 6DOF Pos ...

  7. vue.js---methods中一个方法调用另一个方法

    new Vue({ el: '#app', data: { test:111, }, methods: { test1:function(){ alert(this.test) }, test2:fu ...

  8. c++PrimerChap7类

    仅仅记录贴,按书上的做完了一边,想把private分离出来已经很难了.因为is用到的成员变量都是直接当做public使用的,如果要改的话可以考虑存储输入,让后用构造函数对类进行初始化. #includ ...

  9. layui框架下的摸索与学习

    一.table表格内的查询  1.单个条件查询: 主要代码: <%-- Created by IntelliJ IDEA. User: Administrator Date: 2019/1/14 ...

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

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