注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
没想到那么简单,求大米
T1: Given an array `arr` of `n` non-negative integers and an array `power` of `k` integers where `k` is an even number, perform the following operation in steps.
- Select two integers `i` and `j` such that `0 ≤ i < j < |power|`. In each operation, `i` and `j` are selected independently.
- If `power[i] = power[j]`, add the summation of the subarray `arr[power[i]...power[j]]` to the power.
- If `power[i] > power[j]`, add the summation of the subarray `arr[power[j]...power[i]]` to the power.
- Delete `i`-th and `j`-th elements from `power`, and its length is reduced by 2.
Starting at 0 initial power, maximize the final power after exactly `k/2` operations. Return that maximum power modulo `(10^9 + 7)`.
**Note:** Subarray `arr[l...r]` denotes the subarray formed by the elements `arr[l], arr[l+1], ..., arr[r-1], arr[r]`.
#### Example:
```
arr = [3, 5, 6, 0, 7], power = [3, 1, 0, 2]
k = 4, the size of power, so perform k/2 = 2 operations.
```
One of the optimal approaches is shown:
```
- Select i=0, j=2. Here, power[0] = 3 and power[2] = 0. Add the sum of subarray `arr[0...3]` (3 + 5 + 6 + 0 = 14) to the power. 0 + 14 = 14. Remove the two elements from power, and power is [1, 2].
- Select i=0, j=1. Here, power[0] = 1 and power[1] = 2. Add the sum of subarray `arr[1...2]` 5 + 6 = 11, so power is 14 + 11 = 25.
```
题解
您好! 本帖隐藏的内容需要积分高于 123 才可浏览 您当前积分为 0。 使用VIP即刻解锁阅读权限或查看其他获取积分的方式 游客,您好! 本帖隐藏的内容需要积分高于 123 才可浏览 您当前积分为 0。 VIP即刻解锁阅读权限 或 查看其他获取积分的方式
T2:
Given a permutation `p` of length `n` denoted by `p = [p1, p2,..., pn]`, a number `k` is balanced if there are two indices `l`, `r` (1 ≤ l ≤ r ≤ n), such that the numbers `[p[l], p[l+1], ..., p[r]]` form a permutation of the numbers `1, 2, ..., k`.
For each `k` (1 ≤ k ≤ n), determine if it is a balanced number or not. Return a binary string `ans` of length `n`, where the `i-th` character of the string (considering 1-based indexing) is '1' if `i` is a balanced number and '0' otherwise.
**Note:** A permutation of length `n` contains each integer from 1 to `n` exactly once in any order.
#### Example:
Consider `n = 4`, `p = [4, 1, 3, 2]`.
- For `k = 1`: Choose `l = 2` and `r = 2`, the chosen `p[2:2] = {1}`, a permutation of length 1.
- For `k = 2`: No pair of indices results in a permutation of length 2. It is not a balanced number.
- For `k = 3`: `l = 2, r = 4, p[2:4] = [1, 3, 2], a permutation of length 3.
- For `k = 4`, `l = 1, r = 4, p[1:4] = [4, 1, 3, 2], a permutation of length 4.
The balanced numbers are 1, 3, and 4, while 2 is not balanced. The answer is `"1011"`.
题解
您好! 本帖隐藏的内容需要积分高于 123 才可浏览 您当前积分为 0。 使用VIP即刻解锁阅读权限或查看其他获取积分的方式 游客,您好! 本帖隐藏的内容需要积分高于 123 才可浏览 您当前积分为 0。 VIP即刻解锁阅读权限 或 查看其他获取积分的方式
选择题还是比较简单的
您好! 本帖隐藏的内容需要积分高于 123 才可浏览 您当前积分为 0。 使用VIP即刻解锁阅读权限或查看其他获取积分的方式 游客,您好! 本帖隐藏的内容需要积分高于 123 才可浏览 您当前积分为 0。 VIP即刻解锁阅读权限 或 查看其他获取积分的方式
|