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. ubuntu更改mysql配置文件,使其产生日志文件mysql.log

    1.打开mysql配置文件,将68,69行的注释取消掉,保存关闭 sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 2.重启mysql服务 sudo servic ...

  2. 摇一摇—微信7.0.8版本audio无法自动播放问题

    近日有一个项目出现audio无法自动播放,查看原因才发现是微信版本更新为7.0.8版本,需要有交互行为,第一次播放需要用户手动点击一下,无法使用DOM中的play()进行直接播放操作,那怎么办呢? 通 ...

  3. javaWeb快速入门+——初体验-HelloWorld

    文章转载自 https://www.cnblogs.com/1906859953Lucas/p/10821840.html 练习成品下载 https://www.lanzous.com/i9fljkj ...

  4. normalization flow

    from Eric Jang Normalizing flows transform simple densities (like Gaussians) into rich complex distr ...

  5. windows 服务启动外部程序

    服务使用Process启动外部程序没窗体 在WinXP和Win2003环境中,安装服务后,右键单击服务“属性”-“登录”选项卡-选择“本地系统帐户”并勾选“允许服务与桌面交互”即可. 在Win7及以后 ...

  6. gogs迁移至gitlab

    一.先来聊一聊迁移的思路,不管是gogs迁移至gitlab,还是gitlab迁移至gogs,亦或gitlab迁移至gitlab,手动迁移的步骤都是如下图所示(在gitlab上新建一个空项目就会有这样的 ...

  7. python3练习100题——029

    原题链接:http://www.runoob.com/python/python-exercise-example29.html 题目:给一个不多于5位的正整数,要求:一.求它是几位数,二.逆序打印出 ...

  8. js中事件代理(委托)

    var oul = document.getElementById(‘uli’); oul.onclick = function(e) { e = e || window.event; var tar ...

  9. Python爬虫连载8-JS加密(一)

    一.JS加密 1.有的反爬虫策略采用js对需要传输的数据进行加密处理. 2.经过加密,传输的就是密文 3.加密函数或者过程一定是在浏览器完成,也就是一定会把代码(js代码)暴露给使用者 4.通多阅读加 ...

  10. 巨杉Tech | SparkSQL+SequoiaDB 性能调优策略

    当今时代,企业数据越发膨胀.数据是企业的价值,但数据处理也是一种技术挑战.在海量数据处理的场景,即使单机计算能力再强,也无法满足日益增长的数据处理需求.所以,分布式才是解决该类问题的根本解决方案.而在 ...