#P16440. [XJTUPC 2026] 公式战士
[XJTUPC 2026] 公式战士
Problem Description
You must have seen these blood-pressure-rising game ads on social media or short-video apps: the player controls a character with a pitiful combat power value. Facing two doors labeled “” and “”, the player still walks to “” without hesitation, and in the end gets mercilessly defeated by a high-level monster.
Every time you see such a video, you want to jump into the screen and play for them. Now, you have finally downloaded this game called “Formula Warriors”, and you decide to play it yourself, break the stupid operations in the ads, and show everyone what a true strongest warrior looks like.
Initially, the warrior you control has combat power equal to a positive integer .
The game has levels. In each level, there are doors in front of the warrior, and the warrior must and can only choose one door to pass through.
Each door has a formula on it. When the warrior passes through the door, the warrior’s combat power becomes:
$$x \leftarrow \lfloor\text{Expression1} \ \ \text{Operator} \ \ \text{Expression2}\rfloor$$Where:
- is one of the four operators: add (), subtract (), multiply (), divide ().
- In and , exactly one is the warrior’s current combat power , and exactly one is the given positive integer constant on the door.
- means taking the floor of .
It is guaranteed that no matter what legal choices you make in the game, after completing the -th operation (), the warrior’s current combat power always satisfies .
You need to plan these choices properly so that after passing all levels, the final combat power is maximized. Output the maximum possible combat power.
Input Format
This problem contains multiple test cases. The first line of input contains a positive integer (), representing the number of test cases.
Next are descriptions of test cases.
The first line of each test case contains two positive integers and (, ), separated by a space, representing the number of levels and the warrior’s initial combat power.
The next lines describe the formulas on the doors of level . Each line contains space-separated elements: the first elements describe the first door, and the last elements describe the second door.
For each door, the given elements strictly follow the format $\text{Expression1} \ \ \text{Operator} \ \ \text{Expression2}$, where:
- is one of the characters , , , , representing addition, subtraction, multiplication, and division.
- In and , exactly one is the character , representing the player’s current combat power; exactly one is a positive integer (), representing the constant given on the door.
For example, means updating combat power to ; means updating combat power to .
It is guaranteed that no matter what legal choices you make in the game, after completing the -th operation (), the warrior’s current combat power always satisfies .
It is guaranteed that the sum of over all test cases does not exceed .
Output Format
For each test case, output one line containing an integer, representing the maximum combat power the warrior can obtain after passing levels.
2
3 2
x + 3 x * 2
100 / x x * 10
x - 10 1000 / x
1 1145141919810
1145141919810 + x 3 * x
50
3435425759430
Hint
In sample test case 1, one optimal choice is: first door first door second door.
The corresponding combat power changes are: .
Translated by ChatGPT 5