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的更多相关文章

  1. CF1146G Zoning Restrictions

    CF1146G Zoning Restrictions 网络流 h<=50? 直接都选择最大的,ans=n*h*h 最小割 考虑舍弃或者罚款 有一个>x就要罚款? 经典取值限制的模型:切糕 ...

  2. Codeforces1146G. Zoning Restrictions

    Description You are planning to build housing on a street. There are n spots available on the street ...

  3. 【CF1146】Forethought Future Cup - Elimination Round

    Forethought Future Cup - Elimination Round 窝也不知道这是个啥比赛QwQ A. Love "A" 给你一个串,你可以删去若干个元素,使得最 ...

  4. CF集萃2

    CF1155D - Beautiful Array 题意:给你一个序列和x,你可以选择任意一个子串(可以为空)乘上x,使得得到的序列最大子串和最大.求这个最大值.30w,2s. 解:设fi,0/1/2 ...

  5. Codeforces Gym 100803C Shopping 贪心

    Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopp ...

  6. 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 ...

  7. Codeforces Round #143 (Div. 2) (ABCD 思维场)

    题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. python3练习100题——051

    题目:学习使用按位与 & . 不会的知识点,查了一下按位运算. 按位运算符是把数字看作二进制来进行计算的. 运算符 描述 实例 & 按位与运算符:参与运算的两个值,如果两个相应位都为1 ...

  2. vue koa2 mongodb 从零开始做个人博客(二) 登录注册功能后端部分

    0.效果演示 插入视频插不进来,就很烦.可以出门右拐去优酷看下(点我!). 1.后端搭建 1.1项目结构 首先看一下后端的server目录 挨个解释一下 首先dbs文件夹顾名思义,操作数据库的,mod ...

  3. k8s获取apiversion下面的对应可用资源

    1- 获取api命令 [注:以下命令的url地址http://127.0.0.1/为k8s master的地址] kubectl api-versions 输出内容如下: apps/v1beta1 a ...

  4. 【Unity|C#】基础篇(20)——枚举器与迭代器(IEnumerable/IEnumerator)

    [学习资料] <C#图解教程>(第18章):https://www.cnblogs.com/moonache/p/7687551.html 电子书下载:https://pan.baidu. ...

  5. JAVA StringUtils工具类

    org.apache.commons.lang Class StringUtils java.lang.Object org.apache.commons.lang.StringUtils publi ...

  6. 【巨杉数据库Sequoiadb】点燃深秋,巨杉数据库亮相DTC数据技术嘉年华大会

    2019年11月15日,第九届数据技术嘉年华大会在北京隆重召开,本次大会以  “开源 • 智能 • 云数据 - 自主驱动发展 创新引领未来” 为主题,探索数据价值,共论智能未来.SequoiaDB 巨 ...

  7. Flask知识总结

    1.-----------------路由设置的2种方式----------------- 查看源码,route方法里,本质是执行app.add_url_rule() 因此可以这么写(主流方式): @ ...

  8. POJ1273【网络流】

        Drainage Ditches   Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 91824   Accepted ...

  9. 在SQL中怎么把一列字符串拆分为多列

    --首先,你是按什么规则拆? 我举个例子 你要按字段中的逗号拆开,假设字段名叫text --用charindex和substring这2个函数    select substring(text,1,c ...

  10. C++——字符串处理

    11.用字符数组存储和处理字符串 字符数组的声明和引用  字符串: 字符串常量 “china”,没有字符串变量,用字符数组来存放字符串,字符串以‘\0’结束. 字符串数组的初始化: 逐个输出输入字符串 ...