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,一经查实,立即删除!

相关文章

你和大牛差了啥

mmp。无时无刻不在想和大牛差在哪里了。别人为什么可以那么牛逼而你tmd那么菜&#xff01;整个人顿时都颓废了。啥事儿不想干。后来想了想感情就是他比较黑吧。

[转载] python数组的使用

参考链接&#xff1a; Python中整数的最大可能值是多少&#xff1f; 原文地址为&#xff1a; python数组的使用 python数组的使用 python数组的使用 2010-07-28 17:17 1、Python的数组分三种类型&#xff1a; (1) list 普通的链表&#xff0c;初始化后可以通过特定方法…

scala中循环守卫_Scala中的循环

scala中循环守卫Scala中的循环 (Loops in Scala) In programming, many times a condition comes when we need to execute the same statement or block of code more than one time. It could be difficult to write the same code multiple times, so programing language d…

50个必备基础命令

1.tar创建一个新的tar文件$ tar cvf archive_name.tar dirname/解压tar文件$ tar xvf archive_name.tar查看tar文件$ tar tvf archive_name.tar2. grep在文件中查找字符串(不区分大小写)$ grep -i "the" demo_file输出成功匹配的行&#xff0c;以及该行之后的三行$ g…

NM的完整形式是什么?

NM&#xff1a;无消息 (NM: No Message) NM is an abbreviation of "No Message". NM是“无消息”的缩写。 It is an expression, which is commonly used in the Gmail platform. It is also written as N/M or n/m or *n/m*. It is written in the subject of the…

[转载] python中全局变量和局部变量解析

参考链接&#xff1a; Python中的全局变量和局部变量 python函数中可以访问全局变量但是不能给全局变量赋值&#xff0c;除非进行显式声明global a 比如定义了全局变量 a 在函数my_fun()中可以直接访问a的值&#xff0c;而不需要global全局变量申明。下图为上面代码运行输出 …

【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-----------------------------------------------…

[转载] Python中TFTP的理解

参考链接&#xff1a; Python中的打包pack和拆包unpack参数 Num01–>TFTP协议介绍 TFTP&#xff08;Trivial File Transfer Protocol,简单文件传输协议&#xff09; 是TCP/IP协议族中的一个用来在客户端与服务器之间进行简单文件传输的协议 特点&#xff1a; 1,简单 2…

gn fast-gn_GN的完整形式是什么?

gn fast-gnGN&#xff1a;晚安 (GN: Good Night) GN is an abbreviation of "Good Night". GN是“ Good Night”的缩写 。 It is an expression, which is commonly used in messaging or chatting on social media networking sites like Facebook, Yahoo Messenge…

从零开始编写自己的C#框架(27)——什么是开发框架

前言 做为一个程序员&#xff0c;在开发的过程中会发现&#xff0c;有框架同无框架&#xff0c;做起事来是完全不同的概念&#xff0c;关系到开发的效率、程序的健壮、性能、团队协作、后续功能维护、扩展......等方方面面的事情。很多朋友在学习搭建自己的框架&#xff0c;很多…

[转载] Python 递归 深入理解递归 Python递归剖析,绝对让你看懂!

参考链接&#xff1a; Python | print()中的结束参数 目录 递归剖析 递归的两个过程 return 返回值 详解 递归思路二分法和递归尾递归递归练习题 递归剖析 递归真的很重要&#xff0c;之前学的时候&#xff0c;学的一知半解&#xff0c;以为真正了解&#xff0c;每次想到递归…

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…

Python之list对应元素求和

本次分享将讲述如何在Python中对多个list的对应元素求和&#xff0c;前提是每个list的长度一样。比如&#xff1a;a[1,2,3], b[2,3,4], c[3,4,5], 对a,b,c的对应元素求和&#xff0c;输出应为[6,9,12].    方法一&#xff1a;   直接求解&#xff0c;按照对应元素相加的…

[转载] Python中str跟int的转换

参考链接&#xff1a; Python中的类型转换 字符串str转换成int: int_value int(str_value) int转换成字符串str: str_value str(int_value) a100 b666 #int转str类型 print(int转str类型) print(int转str&#xff1a; str(a)) #str转int类型 print(str转int类型…

ot协议是什么_OT的完整形式是什么?

ot协议是什么OT&#xff1a;主题外 (OT: Off Topic) OT is an abbreviation of "Off Topic". OT是“ Off Topic”的缩写 。 It is an expression, which is commonly used in Gmail or messaging platform. It shows that the email that has been sent is irrelev…

[转载] python中字符串编码形式及其所占字节

参考链接&#xff1a; Python中的字节对象与字符串 1.常见字符串编码错误 在使用Python读文件时经常遇到编码问题引起的错误&#xff0c;比如&#xff1a; UnicodeDecodeError: gbk codec cant decode byte 0x80 in position 30: illegal multibyte sequence 遇到这种异…

[AtCoder-ARC073F]Many Moves

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

ScalavsKotlin

Is Scala better that Kotlin? No..., Is Kotlin better than Scala? No... Scala比Kotlin更好吗&#xff1f; 不...&#xff0c;Kotlin胜过Scala吗&#xff1f; 没有... Both programming languages have their own profits and are for a specific set of development. It…

工业智能相机与基于PC的机器视觉的区别比较

随着科技的日渐成熟&#xff0c;机器视觉得到了飞速发展。由于嵌入式技术的发展,近几年智能相机性能显著提高&#xff0c;越来越多必须依赖于PC处理的应用开始向智能相机平台倾斜。低成本、高可靠性及易于安装维护等优势&#xff0c;使得机器视觉在制造业上的规模性应用越来越普…

[转载] python skimage在图像处理中的用法

参考链接&#xff1a; 在Python中打印单变量和多变量 基于python脚本语言开发的数字图片处理包&#xff0c;比如PIL,Pillow, opencv, scikit-image等。 PIL和Pillow只提供最基础的数字图像处理&#xff0c;功能有限&#xff1b;opencv实际上是一个c库&#xff0c;只是提供了py…