Maximum Product UVA - 11059

本文介绍了一种算法,用于找出整数序列中具有最大正乘积的连续子序列。该算法通过遍历序列并计算所有可能连续子序列的乘积来确定最大乘积。

 注意:是序列,有顺序的,有顺序的,有顺序的。

Given a sequence of integers S = {S1, S2, . . . , Sn}, you should determine what is the value of the maximum positive product involving consecutive terms of S. If you cannot find a positive sequence, you should consider 0 as the value of the maximum product.

Input

Each test case starts with 1 ≤ N ≤ 18, the number of elements in a sequence. Each element Si is an integer such that −10 ≤ Si ≤ 10. Next line will have N integers, representing the value of each element in the sequence. There is a blank line after each test case. The input is terminated by end of file (EOF).

Output

For each test case you must print the message: ‘Case #M: The maximum product is P.’, where M is the number of the test case, starting from 1, and P is the value of the maximum product. After each test case you must print a blank line.

Sample Input

3

2 4 -3

 

5

2 5 -1 2 -1

Sample Output

Case #1: The maximum product is 8.

 

Case #2: The maximum product is 20.

#include <stdio.h>

int main()
{
    int num[100000];
    int h = 1, n, i, j;
    while(scanf("%d", &n) != EOF)
    {
        for(i = 0; i < n; i++)
        {
            scanf("%d", &num[i]);
        }
        long long maxn = 0;
        for(i = 0; i < n; i++)
        {
            long long product = 1;
            for(j = i; j < n; j++)
            {
                product *= num[j];
                if(product > maxn)
                {
                    maxn = product;
                }
            }
        }
        printf("Case #%d: The maximum product is %lld.\n", h++, maxn);
        printf("\n");
    }
    return 0;
}

 

<think>我们正在讨论YARN调度器中的`yarn.scheduler.maximum-allocation-vcores`参数。根据用户提供的引用,特别是引用[2]和引用[5],我们可以总结如下:1.**参数含义**:`yarn.scheduler.maximum-allocation-vcores`定义了集群中单个容器(Container)可以请求的最大虚拟核心数(vcores)。任何容器请求的vcores超过这个值都会被限制到该最大值。2.**默认值**:根据引用[5],默认值为4。3.**配置位置**:在`yarn-site.xml`文件中配置。4.**业务设置**:引用[2]提到,根据业务需求设置,并且指出经过Cloudera测试,vcores小于5时性能最佳(因此他们设置最大为4c)。5.**与最小值的关联**:该参数通常与`yarn.scheduler.minimum-allocation-vcores`(容器请求的最小vcores)一起使用,共同定义了容器vcores请求的允许范围。6.**注意事项**:-该参数是集群级别的,对所有队列生效(除非队列有覆盖配置,但通常不是这样)。-在CapacityScheduler中,队列可以有自己的最大资源限制,但容器级别的最大分配仍然受此全局参数限制。-设置太大可能导致大任务垄断资源,设置太小可能限制应用性能。7.**配置示例**(参考引用[2]):```xml<property><name>yarn.scheduler.maximum-allocation-vcores</name><value>4</value></property>```8.**调优建议**:-考虑集群节点资源:例如,如果每个NodeManager配置了32个vcores(如引用[2]所示),则设置最大值不超过节点的vcores数(通常不会超过,因为一个容器只能在一个节点上运行)。-结合应用需求:如果应用中有需要多核的任务(如并行计算),则适当增大;反之,若应用均为轻量任务,则保持较小值以避免大任务占用过多资源。9.**其他相关参数**:-`yarn.nodemanager.resource.cpu-vcores`:每个NodeManager可分配的vcores总数(如32c)。-`yarn.scheduler.minimum-allocation-vcores`:容器请求的最小vcores(如2c)。10.**性能考虑**:引用[2]提到vcores在小于5时性能最佳,所以通常设置最大值为4或5。现在,根据用户要求,回答关于`yarn.scheduler.maximum-allocation-vcores`的配置说明及用法。</think> ### `yarn.scheduler.maximum-allocation-vcores` 配置详解 #### 1. **参数定义与作用** `yarn.scheduler.maximum-allocation-vcores` 是 YARN 资源调度器中的核心参数,用于定义 **单个容器(Container)可申请的最大虚拟核数(vcores)**。作用包括: - **资源隔离限制**:防止单个任务独占集群资源(如配置最大为 4c,则任何容器请求超过 4 vcores 会被强制截断)[^2][^5] - **调度公平性**:与最小值配合实现资源分配的弹性区间,例如: $$ \text{min-vcores} \leq \text{request-vcores} \leq \text{max-vcores} $$ - **防止资源碎片**:避免超大容器导致小任务无法调度 #### 2. **配置规则与关联参数** | **参数** | **默认值** | **依赖关系** | **典型生产环境值** | |---------|-----------|------------|------------------| | `yarn.scheduler.maximum-allocation-vcores` | 4 vcores | 需满足:<br> $$ \text{min-vcores} \leq \text{max-vcores} \leq \text{NodeManager-vcores} $$ | 4-8 vcores(依节点规模)[^2][^5] | | `yarn.scheduler.minimum-allocation-vcores` | 1 vcore | 必须 ≤ max-vcores | 2 vcores[^2] | | `yarn.nodemanager.resource.cpu-vcores` | 8 vcores | max-vcores ≤ 此值 | 32 vcores[^2] | > 💡 **关键约束**:最大分配值受节点物理资源限制,若配置值超过 `yarn.nodemanager.resource.cpu-vcores`,实际生效值为节点最大值。 #### 3. **配置文件示例 (`yarn-site.xml`)** ```xml <configuration> <!-- 单容器最大vcore配置 --> <property> <name>yarn.scheduler.maximum-allocation-vcores</name> <value>4</value> <!-- 通常设置为节点总vcores的1/8~1/4 --> </property> <!-- 关联配置 --> <property> <name>yarn.scheduler.minimum-allocation-vcores</name> <value>2</value> </property> <property> <name>yarn.nodemanager.resource.cpu-vcores</name> <value>32</value> <!-- 节点总vcores --> </property> </configuration> ``` #### 4. **性能优化建议** 1. **CPU密集型场景**: 若运行Spark ML或MPI作业,可适当增大(如 8 vcores),但需遵守: $$ \text{max-vcores} \leq \frac{\text{NodeManager-vcores}}{2} $$ (防止单节点过度竞争) 2. **低延迟场景**: 保持默认 4 vcores 或更低(Cloudera测试表明 vcores < 5 时性能最优[^2]) 3. **与内存协同**: 按比例配置vcores与内存,例如: ```python # 计算vcore与内存的推荐比例 vcore_mem_ratio = yarn.scheduler.maximum-allocation-mb / yarn.scheduler.maximum-allocation-vcores # 通常设置为 2GB/vcore ~ 4GB/vcore ``` #### 5. **队列级覆盖配置(Capacity Scheduler)** 在 `capacity-scheduler.xml` 中可为特定队列单独设置最大值: ```xml <!-- 为research队列设置独立上限 --> <property> <name>yarn.scheduler.capacity.root.research.maximum-allocation-vcores</name> <value>8</value> <!-- 需≤全局max-vcores --> </property> ``` > ⚠️ **注意**:子队列配置不能超过父队列限制[^3][^4] #### 6. **验证配置** 1. 重启 YARN 服务生效 2. 使用命令查看生效值: ```bash yarn rmadmin -getAllServiceConf | grep maximum-allocation-vcores ``` 3. 提交测试任务验证: ```bash yarn jar hadoop-mapreduce-client-testclient.jar \ TestAMRMTokens -container_vcores 5 # 请求5vcores应被拒绝 ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值