codeforces A. Zoning Restrictions Again
A. Zoning Restrictions Again
ou are planning to build housing on a street. There are n spots available on the street on which you can build a house. The spots are labeled from 1 to n from left to right. In each spot, you can build a house with an integer height between 0 and h.
In each spot, if a house has height a, you will gain a2 dollars from it.
The city has m zoning restrictions. The i-th restriction says that the tallest house from spots li to ri (inclusive) must be at most xi.
You would like to build houses to maximize your profit. Determine the maximum profit possible.
Input
The first line contains three integers n, h, and m (1≤n,h,m≤50) — the number of spots, the maximum height, and the number of restrictions.
Each of the next m lines contains three integers li, ri, and xi (1≤li≤ri≤n, 0≤xi≤h) — left and right limits (inclusive) of the i-th restriction and the maximum possible height in that range.
Output
Print a single integer, the maximum profit you can make.
Examples
input
inputCopy
3 3 3
1 1 1
2 2 3
3 3 2
outputCopy
14
inputCopy
4 10 2
2 3 8
3 4 7
outputCopy
262
Note
In the first example, there are 3 houses, the maximum height of a house is 3, and there are 3 restrictions. The first restriction says the tallest house between 1 and 1 must be at most 1. The second restriction says the tallest house between 2 and 2 must be at most 3. The third restriction says the tallest house between 3 and 3 must be at most 2.
In this case, it is optimal to build houses with heights [1,3,2]. This fits within all the restrictions. The total profit in this case is 12+32+22=14.
In the second example, there are 4 houses, the maximum height of a house is 10, and there are 2 restrictions. The first restriction says the tallest house from 2 to 3 must be at most 8. The second restriction says the tallest house from 3 to 4 must be at most 7.
In this case, it’s optimal to build houses with heights [10,8,7,7]. We get a profit of 102+82+72+72=262. Note that there are two restrictions on house 3 and both of them must be satisfied. Also, note that even though there isn’t any explicit restrictions on house 1, we must still limit its height to be at most 10 (h=10).
题意:你需要建很多房屋有n个地方,然后房屋有最初高度限制m,在这城市有t(t属于0-n的闭区间)个路段限制高度ti,建一个房屋你会获利它们高度平的方(美元)
解题思路:开一个数组让数组等于开始总高度限制,然后用这个初始高度数组比较每个路段的高度,取他们的最小值,最后用一个for循环遍历运算求最大的获利
#include"iostream"
#include"algorithm"
#include"math.h"
using namespace std;
int n,m,t,a[],sum,ni,mi,ti;;
int main(){
cin>>n>>m>>t;
for(int i=;i<=n;i++){
a[i]=m;
}
while(t--){
cin>>ni>>mi>>ti;
for(int j=ni;j<=mi;j++)a[j]=min(a[j],ti);
} for(int i=;i<=n;i++) {
sum+=a[i]*a[i];
}
cout<<sum<<endl;
}
codeforces A. Zoning Restrictions Again的更多相关文章
- CF1146G Zoning Restrictions
CF1146G Zoning Restrictions 网络流 h<=50? 直接都选择最大的,ans=n*h*h 最小割 考虑舍弃或者罚款 有一个>x就要罚款? 经典取值限制的模型:切糕 ...
- Codeforces1146G. Zoning Restrictions
Description You are planning to build housing on a street. There are n spots available on the street ...
- 【CF1146】Forethought Future Cup - Elimination Round
Forethought Future Cup - Elimination Round 窝也不知道这是个啥比赛QwQ A. Love "A" 给你一个串,你可以删去若干个元素,使得最 ...
- CF集萃2
CF1155D - Beautiful Array 题意:给你一个序列和x,你可以选择任意一个子串(可以为空)乘上x,使得得到的序列最大子串和最大.求这个最大值.30w,2s. 解:设fi,0/1/2 ...
- Codeforces Gym 100803C Shopping 贪心
Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopp ...
- Codeforces Round #330 (Div. 1) C. Edo and Magnets 暴力
C. Edo and Magnets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/594/pr ...
- Codeforces Round #143 (Div. 2) (ABCD 思维场)
题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...
- Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...
- Codeforces Round #439 (Div. 2) Problem C (Codeforces 869C) - 组合数学
— This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii ...
随机推荐
- Python类的特殊成员方法
__doc__ 类的描述信息. class dog: '''这是狗的类''' def __init__(self,name): self.name = name self.__age = None p ...
- 回溯经典(指定位置N皇后问题)
N皇后问题自不必多说,这道题的先行条件是在放置的时候已经指定了一个棋子的位置. 输入第一行为N,第二行为指定棋子的坐标(x,y):输出方案总数以及按字典序升序的各种方案. 思路: 首先是回溯,其次对待 ...
- 牛客CSP-S提高组赛前集训营3 赛后总结
货物收集 二分答案.复杂度\(O(n\log n)\). 货物分组 用费用提前计算的思想,考虑用一个新的箱子来装货物会发生什么. 显然费用会加上后面的所有货物的总重. \(60\)分的\(O(n^2) ...
- HDFS写入数据
HDFS副本摆放策略 不同的版本副本摆放策略可能并不一致,HDFS主要采用一种机架感知(rack-ware)的机制来实现摆放策略. 由于不同的机架上节点间通信要通过交换机(switches),同一机架 ...
- java自动化测试-json返回值校验
参考: https://blog.csdn.net/xkhgnc_6666/article/details/50250283 实现举例:
- [HAOI2011] 向量 - 裴蜀定理
给你一对数a,b,你可以任意使用(a,b), (a,-b), (-a,b), (-a,-b), (b,a), (b,-a), (-b,a), (-b,-a)这些向量,问你能不能拼出另一个向量(x,y) ...
- 《深入理解Java虚拟机》读书笔记七
第八章 虚拟机字节码执行引擎 1.运行时栈帧结构 概述: 栈帧是用于支持虚拟机进行方法调用的和方法执行的数据结构,他是虚拟机运行时数据区中的虚拟机栈的栈元素,栈帧存储了方法的局部变量,操作数栈,动态连 ...
- 题解【BZOJ4472】[JSOI2015]salesman
题面 树形\(\text{DP}\)与贪心的结合. 首先考虑树形\(\text{DP}\). 设\(dp_i\)表示从\(i\)出发,访问\(i\)的子树,并且最后回到\(i\)能获得的最大收益. 转 ...
- 用户注册代码(php)
<!DOCTYPE HTML><html><head><meta charset="utf-8"><script type=& ...
- 终极教程【zhong】
just for a better future! 资源教程 aiim 综合类 前端知识体系 前端知识结构 Web前端开发大系概览 We ...