牛客多校2 D-money(dp记录/贪心)
D-money
链接:https://www.nowcoder.com/acm/contest/140/D
来源:牛客网
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld
题目描述
White Rabbit wants to visit these stores in the order from 1 to n.
The store numbered i has a price a[i] representing that White Rabbit can spend a[i] dollars to buy a product or sell a product to get a[i] dollars when it is in the i-th store.
The product is too heavy so that White Rabbit can only take one product at the same time.
White Rabbit wants to know the maximum profit after visiting all stores.
Also, White Rabbit wants to know the minimum number of transactions while geting the maximum profit.
Notice that White Rabbit has infinite money initially.
输入描述:
The first line contains an integer T(0<T<=5), denoting the number of test cases.
In each test case, there is one integer n(0<n<=100000) in the first line,denoting the number of stores.
For the next line, There are n integers in range [0,2147483648), denoting a[1..n].
输出描述:
For each test case, print a single line containing 2 integers, denoting the maximum profit and the minimum number of transactions.
输入例子:
1
5
9 10 7 6 8
输出例子:
3 4
-->
输出
3 4
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define MAX 100005
#define INF 0x3f3f3f3f
#define MOD 1000000007
using namespace std;
typedef long long ll; int a[MAX],dpg[MAX][];
ll dpf[MAX][]; int main()
{
int t,n,i,j;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(i=;i<=n;i++){
scanf("%d",&a[i]);
}
memset(dpf,,sizeof(dpf));
memset(dpg,,sizeof(dpg));
dpf[][]=;
dpf[][]=-a[];
dpg[][]=;
dpg[][]=;
for(i=;i<=n;i++){
if(dpf[i-][]>=dpf[i-][]+a[i]){
dpf[i][]=dpf[i-][];
dpg[i][]=dpg[i-][];
}
else{
dpf[i][]=dpf[i-][]+a[i];
dpg[i][]=dpg[i-][]+;
}
if(dpf[i-][]-a[i]>dpf[i-][]){
dpf[i][]=dpf[i-][]-a[i];
dpg[i][]=dpg[i-][]+;
}
else{
dpf[i][]=dpf[i-][];
dpg[i][]=dpg[i-][];
}
}
printf("%lld %d\n",dpf[n][],dpg[n][]);
}
return ;
}
牛客多校2 D-money(dp记录/贪心)的更多相关文章
- 2019牛客多校第四场D-triples I 贪心
D-triples 题意 给你一个\(n\),问至少有几个数或运算起来可以等于\(n\),并且输出数量和这个几个数.题目说明给的\(n\)一定符合条件(不会输出\(n= 1\) 之类不存在情况). 思 ...
- 2019牛客多校第一场 I Points Division(动态规划+线段树)
2019牛客多校第一场 I Points Division(动态规划+线段树) 传送门:https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点有 ...
- 2019牛客多校第八场 F题 Flowers 计算几何+线段树
2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...
- 2019牛客多校 Round4
Solved:3 Rank:331 B xor 题意:5e4个集合 每个集合最多32个数 5e4个询问 询问l到r个集合是不是都有一个子集的xor和等于x 题解:在牛客多校第一场学了线性基 然后这个题 ...
- 牛客多校第一场 B Inergratiion
牛客多校第一场 B Inergratiion 传送门:https://ac.nowcoder.com/acm/contest/881/B 题意: 给你一个 [求值为多少 题解: 根据线代的知识 我们可 ...
- 2019牛客多校第二场 A Eddy Walker(概率推公式)
2019牛客多校第二场 A Eddy Walker(概率推公式) 传送门:https://ac.nowcoder.com/acm/contest/882/A 题意: 给你一个长度为n的环,标号从0~n ...
- 牛客多校第三场 F Planting Trees
牛客多校第三场 F Planting Trees 题意: 求矩阵内最大值减最小值大于k的最大子矩阵的面积 题解: 矩阵压缩的技巧 因为对于我们有用的信息只有这个矩阵内的最大值和最小值 所以我们可以将一 ...
- 牛客多校第三场 G Removing Stones(分治+线段树)
牛客多校第三场 G Removing Stones(分治+线段树) 题意: 给你n个数,问你有多少个长度不小于2的连续子序列,使得其中最大元素不大于所有元素和的一半 题解: 分治+线段树 线段树维护最 ...
- 牛客多校第四场sequence C (线段树+单调栈)
牛客多校第四场sequence C (线段树+单调栈) 传送门:https://ac.nowcoder.com/acm/contest/884/C 题意: 求一个$\max {1 \leq l \le ...
随机推荐
- 【题解】P3129高低卡(白金)High Card Low Card
[题解][P3129 USACO15DEC]高低卡(白金)High Card Low Card (Platinum) 考虑贪心. 枚举在第几局改变规则,在改变规则之前,尽量出比它大的最小的牌,在改变规 ...
- cordova 实现拨打电话-只需两步(H5)
cordova 实现拨打电话: 第一步配置conf.xml在cordova中所有的URL Schemes 都是服从于白名单的,所以a tel 在这无法正常使用.解决方法是在项目config.xml中添 ...
- Swift 烧脑体操(三) - 高阶函数
前言 Swift 其实比 Objective-C 复杂很多,相对于出生于上世纪 80 年代的 Objective-C 来说,Swift 融入了大量新特性.这也使得我们学习掌握这门语言变得相对来说更加困 ...
- android的GPS代码分析JNI如何HAL之间如何设置回调函数【转】
本文转载自:http://blog.csdn.net/kmesg/article/details/6531577 本文只关注JNI和HAL的接口部分 在jni的android_location_Gps ...
- POJ1185 炮兵阵地 —— 状压DP
题目链接:http://poj.org/problem?id=1185 炮兵阵地 Time Limit: 2000MS Memory Limit: 65536K Total Submissions ...
- ES搜索排序,文档相关度评分介绍——Vector Space Model
Vector Space Model The vector space model provides a way of comparing a multiterm query against a do ...
- 解决Linux Kettle出现闪退问题
linux环境, 运行sh spoon.sh打开图形化界面时经常出现闪退情况. 报错信息如下: cfgbuilder - Warning: The configuration parameter [o ...
- #基础概念#之tensor
中译名:张量 定义: from wiki: In mathematics, tensors are geometric objects that describe linear relations b ...
- CodeForcesdiv1:995C - Leaving the Bar(随机算法+贪心)
For a vector →v=(x,y)v→=(x,y), define |v|=√x2+y2|v|=x2+y2. Allen had a bit too much to drink at the ...
- java-03 方法
#############练习###################### 1.键盘录入乘法表 import java.util.Scanner; public class PrintNN { pub ...