cesium广告牌_公路广告牌

cesium广告牌

Description:

描述:

This is a standard dynamic programing problem of finding maximum profits with some constraints. This can be featured in any interview coding rounds.

这是在某些约束条件下找到最大利润的标准动态编程问题。 这可以在任何采访编码回合中体现。

Problem statement:

问题陈述:

Consider a highway of M miles. The task is to place billboards on the highway such that revenue is maximized. The possible sites for billboards are given by number x1 < x2 < ... < x(n-1) < xn specifying positions in miles measured from one end of the road. If we place a billboard at position xi, we receive a revenue of ri > 0. The constraint is that no two billboards can be placed within t miles or less than it.

考虑一条M英里的高速公路。 任务是在高速公路上放置广告牌,以使收入最大化。 广告牌的可能位置由数字x 1 <x 2 <... <x (n-1) <x n给出,指定从道路的一端算起的英里位置。 如果将广告牌放置在x i位置,我们的收入r i > 0 。 约束条件是在t英里以内或小于t英里内不能放置两个广告牌。

    Input:
M=15, n=5
x[n]= {6,8,12,14,15}
revenue[n] = {3,6,5,3,5}
t = 5
Output:
11

Explanation with example

举例说明

So, we have to maximize the revenue by placing the billboards where the gap between any two billboard is t.

因此,我们必须通过将广告牌放置在任意两个广告牌之间的距离为t的位置来最大化收入。

Here,

这里,

The corresponding distances of the billboards with respect to the origin are,

广告牌相对于原点的相应距离为

    x[5]= {6,8,12,14,15}

We can augment the origin, so the augmented array becomes: (no need to augment if origin revenue exists)

我们可以扩充原点,因此扩充后的数组将变为:(如果存在原点收入,则无需扩充)


x[6]= {0,6,8,12,14,15}
t=5

The graphical interpretation of the billboards is like following:

广告牌的图形解释如下:

Highway billboard


Figure 1: Billboards

图1:广告牌

The augmented revenue array:

扩充收益阵列:

    revenue[6] = {0,3,6,5,3,5}

Now, the brute force approach can be to check all the possible combination of billboards and updating the maximum revenue accumulated from each possible combinations.

现在,暴力破解方法可以是检查广告牌的所有可能组合,并更新每个可能组合所累积的最大收益。

Few of such possible combinations can be:

这样的可能组合很少是:

Highway billboard

So, maximum revenue that can be collected is 11.

因此,可以收取的最大收入为11

For any billboard bi we have three choices

对于任何广告牌b 都有三种选择

  1. Don't pick bi

    不要选择

  2. Start from bi

    开始

  3. Pick bi and other billboards accordingly

    相应地选择b i和其他广告牌

Say,

说,

    M(i)=maximum revenue upto first i billboards

So,

所以,

    M(0)=0
if bi is not picked, M(i)=M(i-1)
if billboard placement starts from bi M(i)=r[i]
If we place bi then need to pace bj where d[i]>d[j]-t such that revenue maximizes
So,

Highway billboard

Problem Solution approach

问题解决方法

We convert the above recursion to dynamic programing as there will many overlapping sub problems solving the recursion. (Try to generate the recursion tree yourself)

我们将上述递归转换为动态编程,因为将会有许多重叠的子问题解决递归。 (尝试自己生成递归树)

    1) Construct DP[n] for n billboards
// considering billboard placing starts from it
2) Fill the array with base value which is r[i] 
3) for  i=1 to n-1
// recursion case 1 and 2
// either not picking ith billboard or starting 
// from ith billboard which ever is maximum
dp[i] = max(dp[i-1],dp[i]);
// recursion case 3
// picking ith billboard
for j=0 to i-1
if(a[j]< a[i]-k)//feasible placing
dp[i]= max(dp[i],dp[j]+r[i]);
end for
end for
Result is dp[n-1]

C++ implementation:

C ++实现:

#include <bits/stdc++.h>
using namespace std;
int max(int x, int y)
{
return (x > y) ? x : y;
}
int billboard(vector<int> a, vector<int> r, int n, int k)
{
int dp[n];
for (int i = 0; i < n; i++)
dp[i] = r[i];
//base value
dp[0] = r[0];
for (int i = 1; i < n; i++) {
//first two recursion case
int mxn = max(dp[i - 1], dp[i]);
//picking ith billboard, third recursion case
for (int j = 0; j < i; j++) {
if (a[j] < a[i] - k)
mxn = max(mxn, dp[j] + r[i]);
}
dp[i] = mxn;
}
return dp[n - 1];
}
int main()
{
int n, k, item, m;
cout << "Enter highway length:\n";
cin >> m;
cout << "Enter number of billboards\n";
cin >> n;
cout << "Enter minimum distance between any two billboards\n";
cin >> k;
vector<int> a;
vector<int> r;
cout << "Enter billboard distances one by one from origin\n";
for (int i = 0; i < n; i++) {
cin >> item;
a.push_back(item);
}
cout << "Enter revenues for the respective billboards\n";
for (int i = 0; i < n; i++) {
cin >> item;
r.push_back(item);
}
if (a[0] == 0) {
a.insert(a.begin(), 0);
r.insert(r.begin(), 0);
n = n + 1;
}
cout << "Maximum revenue that can be collected is: " << billboard(a, r, n, k) << endl;
return 0;
}

Output

输出量

RUN 1:
Enter highway length:
20
Enter number of billboards
5
Enter minimum distance between any two billboards
5
Enter billboard distances one by one from origin
3 7 12 13 14
Enter revenues for the respective billboards
15 10 1 6 2
Maximum revenue that can be collected is: 21
RUN 2:
Enter highway length:
15
Enter number of billboards
5
Enter minimum distance between any two billboards
5
Enter billboard distances one by one from origin
6 8 12 14 15
Enter revenues for the respective billboards
3 6 5 3 5
Maximum revenue that can be collected is: 11

翻译自: https://www.includehelp.com/icp/highway-billboard.aspx

cesium广告牌

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/540573.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【iCore4 双核心板_FPGA】例程十六:基于双口RAM的ARM+FPGA数据存取实验

实验现象&#xff1a; 核心代码&#xff1a; int main(void) {/* USER CODE BEGIN 1 */int i;int address,data;char error_flag 0;char receive_data[50];char buffer[8];char *p;/* USER CODE END 1 *//* MCU Configuration-----------------------------------------------…

laravel 项目迁移_在Laravel迁移

laravel 项目迁移Before moving forward we need to know some facts about it, 在继续前进之前&#xff0c;我们需要了解一些事实&#xff0c; Resources: In these directories, we have already a js, lang, sass and view page. Where, sass and js file holf their uncom…

[AtCoder-ARC073F]Many Moves

题目大意&#xff1a;   有一排n个格子和2枚硬币。   现在有q次任务&#xff0c;每一次要你把其中一枚硬币移到x的位置上&#xff0c;移动1格的代价是1。   两枚硬币不能同时移动&#xff0c;任务必须按次序完成。   现在告诉你两枚硬币初始状态所在的位置a和b&#xf…

OpenStack —— DevStack一键自动化安装

一、DevStack介绍Devstack目前是支持Ubuntu16.04和CentOS 7&#xff0c;而且Devstack官方建议使用Ubuntu16.04&#xff0c;所以我们使用Ubuntu 16.04进行安装。默认无论是Devstack和OpenStack&#xff0c;都是采用Master的代码进行安装&#xff0c;这样经常会出现&#xff0c;今…

Scala铸造

Scala中的类型 (Types in Scala) Type also know as data type tells the compiler about the type of data that is used by the programmer. For example, if we initialize a value or variable as an integer the compiler will free up 4 bytes of memory space and it wi…

OpenCV探索之路(二十五):制作简易的图像标注小工具

搞图像深度学习的童鞋一定碰过图像数据标注的东西&#xff0c;当我们训练网络时需要训练集数据&#xff0c;但在网上又没有找到自己想要的数据集&#xff0c;这时候就考虑自己制作自己的数据集了&#xff0c;这时就需要对图像进行标注。图像标注是件很枯燥又很费人力物力的一件…

图论 弦_混乱的弦

图论 弦Problem statement: 问题陈述&#xff1a; You are provided an input string S and the string "includehelp". You need to figure out all possible subsequences "includehelp" in the string S? Find out the number of ways in which the s…

「原创」从马云、马化腾、李彦宏的对话,看出三人智慧差在哪里?

在今年中国IT领袖峰会上&#xff0c;马云、马化腾、李彦宏第一次单独合影&#xff0c;同框画面可以说很难得了。BAT关心的走势一直是同行们竞相捕捉的热点&#xff0c;所以三位大Boss在这次大会上关于人工智能的见解&#xff0c;也受到广泛关注与多方解读。马云认为机器比人聪明…

字符串矩阵转换成长字符串_字符串矩阵

字符串矩阵转换成长字符串Description: 描述&#xff1a; In this article, we are going to see how backtracking can be used to solve following problems? 在本文中&#xff0c;我们将看到如何使用回溯来解决以下问题&#xff1f; Problem statement: 问题陈述&#xf…

java awt 按钮响应_Java AWT按钮

java awt 按钮响应The Button class is used to implement a GUI push button. It has a label and generates an event, whenever it is clicked. As mentioned in previous sections, it extends the Component class and implements the Accessible interface. Button类用于…

qgis在地图上画导航线_在Laravel中的航线

qgis在地图上画导航线For further process we need to know something about it, 为了进一步处理&#xff0c;我们需要了解一些有关它的信息&#xff0c; The route is a core part in Laravel because it maps the controller for sending a request which is automatically …

Logistic回归和SVM的异同

这个问题在最近面试的时候被问了几次&#xff0c;让谈一下Logistic回归&#xff08;以下简称LR&#xff09;和SVM的异同。由于之前没有对比分析过&#xff0c;而且不知道从哪个角度去分析&#xff0c;一时语塞&#xff0c;只能不知为不知。 现在对这二者做一个对比分析&#xf…

构建安全网络 比格云全系云产品30天内5折购

一年之计在于春&#xff0c;每年的三、四月&#xff0c;都是个人创业最佳的起步阶段&#xff0c;也是企业采购最火热的时期。为了降低用户的上云成本&#xff0c;让大家能无门槛享受到优质高性能的云服务&#xff0c;比格云从3月16日起&#xff0c;将上线“充值30天内&#xff…

数据结构 基础知识

一。逻辑结构: 是指数据对象中数据 素之间的相互关系。 其实这也是我 今后最需要关注的问题 逻辑结构分为以 四种1. 集合结构 2.线性结构 3.数形结构 4&#xff0c;图形结构 二。物理结构&#xff1a; 1&#xff0c;顺序存储结,2 2. 链式存储结构 一&#xff0c;时间复杂…

ruby 变量类中范围_Ruby中的类

ruby 变量类中范围Ruby类 (Ruby Classes) In the actual world, we have many objects which belong to the same category. For instance, I am working on my laptop and this laptop is one of those laptops which exist around the globe. So, this laptop is an object o…

以云计算的名义 驻云科技牵手阿里云

本文讲的是以云计算的名义 驻云科技牵手阿里云一次三个公司的牵手 可能会改变无数企业的命运 2017年4月17日&#xff0c;对于很多人来说可能只是个平常的工作日&#xff0c;但是对于国内无数的企业来说却可能是个会改变企业命运的日。驻云科技联合国内云服务提供商阿里云及国外…

浏览器端已支持 ES6 规范(包括 export import)

当然&#xff0c;是几个比较优秀的浏览器&#xff0c;既然是优秀的浏览器&#xff0c;大家肯定知道是那几款啦&#xff0c;我就不列举了&#xff0c;我用的是 chrome。 对 script 声明 type 为 module 后就可以享受 es6 规范所带来的模块快感了。 基础语法既然是全支持&#xf…

一文读懂深度学习框架下的目标检测(附数据集)

从简单的图像分类到3D位置估算&#xff0c;在机器视觉领域里从来都不乏有趣的问题。其中我们最感兴趣的问题之一就是目标检测。 如同其他的机器视觉问题一样&#xff0c;目标检测目前为止还没有公认最好的解决方法。在了解目标检测之前&#xff0c;让我们先快速地了解一下这个领…

设计一个应用程序,以在C#中的按钮单击事件上在MessageBox中显示TextBox中的文本...

Here, we took two controls on windows form that are TextBox and Button, named txtInput and btnShow respectively. We have to write C# code to display TextBox’s text in the MessageBox on Button Click. 在这里&#xff0c;我们在Windows窗体上使用了两个控件&…

Oracle优化器:星型转换(Star Query Transformation )

Oracle优化器&#xff1a;星型转换&#xff08;Star Query Transformation &#xff09;Star query是一个事实表&#xff08;fact table&#xff09;和一些维度表&#xff08;dimension&#xff09;的join。每个维度表都跟事实表通过主外键join&#xff0c;且每个维度表之间不j…