BAPC 2014 Preliminary(第一场)
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(第一场)的更多相关文章
- 计蒜客 28206.Runway Planning (BAPC 2014 Preliminary ACM-ICPC Asia Training League 暑假第一阶段第一场 F)
F. Runway Planning 传送门 题意简直就是有毒,中间bb一堆都是没用的,主要的意思就是度数大于180度的就先减去180度,然后除以10,四舍五入的值就是答案.如果最后结果是0就输出18 ...
- 计蒜客 28202. Failing Components-最短路(Dijkstra) (BAPC 2014 Preliminary ACM-ICPC Asia Training League 暑假第一阶段第一场 B)
B. Failing Components 传送门 题意就是单向图,从起点开始找最短路,然后统计一下个数就可以.方向是从b到a,权值为s. 直接最短路跑迪杰斯特拉,一开始用数组版的没过,换了一个队列版 ...
- 计蒜客 28201.Choosing Ice Cream-gcd (BAPC 2014 Preliminary ACM-ICPC Asia Training League 暑假第一阶段第一场 A)
开始水一波博客 题目链接: A. Choosing Ice Cream 传送门 题意就是n个冰淇淋,骰子有k个面,问你是否能在公平的概率下转几次骰子能确定买哪个冰淇淋. 举个例子,假设我只有一个冰淇淋 ...
- BAPC 2014 Preliminary
// 题目链接: https://nanti.jisuanke.com/t/282041 //动态规划,重复利用子问题的最优,来求解当前最优问题 #include <iostream> # ...
- 校省选赛第一场C题解Practice
比赛时间只有两个小时,我没有选做这题,因为当时看样例也看不懂,比较烦恼. 后来发现,该题对输入输出要求很低.远远没有昨天我在做的A题的麻烦,赛后认真看了一下就明白了,写了一下,一次就AC了,没问题,真 ...
- 校省选赛第一场A题Cinema题解
今天是学校省选的第一场比赛,0战绩收工,死死啃着A题来做,偏偏一直WA在TES1. 赛后,才发现,原来要freopen("input.txt","r",stdi ...
- 数据结构《21》----2014 WAP 第一个问题----Immutable queue
2014 WAP第一个问题----实现一个不可改变的队列: 看似非常easy.. 其实,不同的版本号之间的效率差距可能是巨大的.. 甚至难以想象. . 使用前STL图书馆queue我们进行了比较.大差 ...
- 计蒜之道 初赛第一场B 阿里天池的新任务(简单)
阿里“天池”竞赛平台近日推出了一个新的挑战任务:对于给定的一串 DNA 碱基序列 tt,判断它在另一个根据规则生成的 DNA 碱基序列 ss 中出现了多少次. 首先,定义一个序列 ww: \displ ...
- hdu 5288||2015多校联合第一场1001题
pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...
随机推荐
- 【跟我一步一步学Struts2】——拦截器
前言 前面提到过拦截器.而且说拦截器仅仅能拦截Action.这里拦截器的调用体现了责任链模式.为什么说体现了责任链模式呢? 以下的一段话说的非常明确: Struts2将整个运行划分成若干同样类型的元素 ...
- php利用msqli访问数据库并实现分页,
<?php require_once 'login.php'; $num_rec_per_page=2; // 每页显示数量 //mysql_connect('localhost','jim', ...
- 神经网络预测mnist时候如果不归一化,则准确率仅仅10%下文作者svm也遇到了。
转自:http://blog.csdn.net/jeryjeryjery/article/details/72649320 这两天用Python来实现手写数字识别,刚开始用原始数据进行训练,结果预测结 ...
- nyoj--891--找点(贪心)
找点 时间限制:2000 ms | 内存限制:65535 KB 难度:2 描述 上数学课时,老师给了LYH一些闭区间,让他取尽量少的点,使得每个闭区间内至少有一个点.但是这几天LYH太忙了,你们帮 ...
- nyoj--528--找球号(三)(位运算&&set)
找球号(三) 时间限制:2000 ms | 内存限制:3000 KB 难度:2 描述 xiaod现在正在某个球场负责网球的管理工作.为了方便管理,他把每个球都编了号,且每个编号的球的总个数都是偶数 ...
- etxjs
序言 编辑 功能丰富,无人能出其右. 无论是界面之美,还是功能之强,ext的表格控件都高居榜首. 单选行,多选行,高亮显示选中的行,拖拽改变列宽度,按列排序,这些基本功能ExtJS轻量级实现. 自动生 ...
- 51nod 1158 全是1的最大子矩阵(单调栈 ,o(n*m))
前置问题:51nod 1102 面积最大的矩形 附上链接: 51nod 1102 面积最大的矩形 这题的题解博客 需要了解的知识:单调栈,在前置问题中已经讲解. 解题思路 对每行求左边连续1的个数,得 ...
- 安装lnmp前请先运行screen
当通过putty或者SecureCRT安装lnmp时, 网络突然掉线或者不小心putty被关掉等等原因, 造成lnmp安装过程被中断怎么办? 其实防止这种现象很简单, 只要在安装lnmp前执行scre ...
- jQuery第三课 点击按钮 弹出层div效果
jQuery 事件方法 事件方法会触发匹配元素的事件,或将函数绑定到所有匹配元素的某个事件. 触发实例: $("button#demo").click() 上面的例子将触发 id= ...
- centos7-centos6常用配置对比
设置(CentOS 6 vs CentOS 7)系统常用配置 ysvinit vs Upstart vs Systemd) 常见设置: 字符集CentOS 6方法:/etc/sysconfig/i1 ...