[闲聊] leetcode - 枫之谷冲装

楼主: yam276 ('_')   2025-06-23 16:31:11
题目:
你是一个枫之谷玩家,你想冲一个 +8 Atk 以上的工地手套
已知一个工地手套成本 50,000 可以冲 5 次
一张 手套攻击卷轴 60% 成本 2,000,000 可以 +2 攻
一张 手套攻击卷轴 10% 成本 1,000,000 可以 +3 攻
计算冲至少 +8 的工地手套需要多少期望成本
测资还会给你随机的基底成本以及卷轴
要求你计算冲到目标数值的期望值
Description
You are enhancing a **weapon** using scrolls.
Each scroll has a **success probability**, **cost**, and **attack bonus** (if
successful).
You may apply **up to `max_scrolls` scrolls**, in a fixed order of your
choosing.
The weapon has a **base cost** (just for the raw item).
Your goal is to produce **one weapon** with **at least `target_attack` total
attack**.
Smart Strategy: Rational Stop-Loss
You are clever. If at any point it becomes **mathematically impossible** to
reach `target_attack` (even if all remaining scrolls succeed), you immediately
stop and discard the weapon to avoid wasting more scrolls.
You pay the cost incurred so far, but not more.
Your job is to determine the **minimum expected total cost** (including
failure attempts) needed to **successfully create one such weapon**, using up
to `max_scrolls`.
Signature
```rust
pub fn min_expected_cost_to_target_attack(
base_cost: u32,
scrolls: Vec<(f64, u32, u32)>,
// (success_probability, cost, attack_bonus)
target_attack: u32,
max_scrolls: usize,
) -> i64;
```
Return
Return the **minimum expected total cost**, in **gold coins**, **rounded down*
* to the nearest integer.
If it is **impossible** to reach `target_attack` even if all scrolls succeed,
return `-1`.
Constraints
* `1 <= base_cost <= 10^7`
* `1 <= scrolls.len() <= 10`
* Each `success_probability` ∈ `(0.0, 1.0)`
* Each `cost <= 10^7`
* Each `attack_bonus <= 10`
* `1 <= target_attack <= 50`
* `1 <= max_scrolls <= 10`
Tags
* `Dynamic Programming`
* `Probability`
* `Expected Value`
* `Recursion`
* `Memoization`
作者: DaibaNana (BANANA)   2025-06-23 16:33:00
10%的现在要200喔
楼主: yam276 ('_')   2025-06-23 16:33:00
100
作者: walter741225 (瓦特)   2025-06-23 16:37:00
要+8感觉要先用10%连过二没有就丢剩下再开始用60%因为现实就是 +8 只容许失败一次而10%要成功两次 才能补足60%失败一次
楼主: yam276 ('_')   2025-06-23 16:38:00
要是我10%能连过2 对ㄚ
作者: walter741225 (瓦特)   2025-06-23 16:39:00
这社会是现实的 对ㄚ
楼主: yam276 ('_')   2025-06-23 16:41:00
可是这题目又不是要你当天选之人==
作者: walter741225 (瓦特)   2025-06-23 16:44:00
只是觉得+8感觉不简单而且这10%真的也好贵 不太划算

Links booklink

Contact Us: admin [ a t ] ucptt.com