#P3798. 辉夜姬的十道难题

    ID: 2737 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>模拟动态规划,dp搜索贪心洛谷原创提交答案剪枝记忆化搜索

辉夜姬的十道难题

Description

20482048 is a very simple number game played on a 4×44 \times 4 board. By moving to merge numbers, reaching 20482048 counts as a win. Meihong has become addicted to the game. When the news reached Kaguya, she decided to test Meihong with ten puzzles that no one had solved before.

Game rules:

  1. The game is played on an n×mn \times m grid.

  2. There are two players. One can move the numbers on the board, denoted by M, and the other can place numbers on the board, denoted by C.

  3. The rules for moving numbers are as follows: you can move in one of the four directions: up/down/left/right. After choosing a direction, all numbers slide toward that direction. When two equal numbers collide, they merge into a new number equal to their sum. In a single move, each tile can merge at most once, and merges prioritize tiles closer to the edge in the movement direction.

For example, when n=2,m=4n=2, m=4 (00 denotes an empty cell):

2 2 2 2
2 2 0 2

After moving left, it becomes:

4 4 0 0
4 2 0 0

After each merge, you gain score equal to the sum of all newly created numbers from merges in that move. If no merges occur, you gain no score. In the example above, the score is 1212.

If, before and after a move, all numbers on the board have the same values and positions, the move is not valid; otherwise, it is a valid move.

  1. The rules for placing numbers are as follows: you may place a number only in an empty cell, and which numbers can be placed and how they are placed are specified in each subtask.

  2. The game starts with an empty board and a score of 00. Player C takes two moves first. Then players M and C alternate moves, and every move in between must be valid. When it is player M’s turn and they cannot make a valid move, the game ends, and the current score is the final score.

This is an output-only problem with 1010 subtasks for you to complete. Write your answers to 1010 files named gamex.out, where xx is the subtask index (090 \ldots 9).

There are no partial points within a subtask; you receive the subtask’s score if and only if your output exactly matches the reference answer.

The ten challenges are as follows:

  1. n=1,m=2n=1, m=2. When player C acts, they may place 22 or 44. Let xx denote the maximum number of moves player M can make in a single game. What are the extremal values of xx? Output two lines: the first line is an integer for the minimum possible xx, and the second line is an integer for the maximum possible xx.

  2. n=10738029,m=921023n=10738029, m=921023. When player C acts, they may place 22 or 44. Let xx be the sum of all numbers on the board. What is the maximum value of xx? Because this value may be too large, output it modulo 109+710^9+7.

  3. n=2,m=2n=2, m=2. When player C acts, they may place 2,42, 4. Let xx denote the target number, where xx is a positive power of 22. Player M’s goal is to make a number at least xx appear on the board, while player C’s goal is to end the game before a number xx appears on the board. Under optimal play by both sides, find the largest xx such that player M can achieve their goal.

  4. n=4,m=4n=4, m=4. When player C acts, they may place 2,42, 4. Output two lines, each with one number. The first line is the maximum achievable score. The second line is the minimum score when the total sum of numbers on the board reaches its maximum.

  5. n=7393,m=9133n=7393, m=9133. Player C can place the number 22 a total of 61446144 times. The board is initially empty and the initial score is 00. First, player C acts consecutively until they use all placement opportunities or voluntarily stop early. Then move upward repeatedly until an upward move is no longer valid. Output one integer on a single line: the maximum score.

  6. n=7,m=233n=7, m=233. The initial score is 00. Player C can place the number 22 a total of 233233 times and the number 44 a total of 6666 times. The first row initially contains some numbers: the number in column ii is lowbit(i)×2\text{lowbit}(i) \times 2, where lowbit(i)\text{lowbit}(i) denotes the number formed by taking only the last 11 in the binary representation of ii. For example, lowbit(18)\text{lowbit}(1 \ldots 8) are 1,2,1,4,1,2,1,81, 2, 1, 4, 1, 2, 1, 8. All other cells are empty. First, player C acts consecutively until they use all placement opportunities or voluntarily stop early. Then move upward repeatedly until an upward move is no longer valid. Output one integer on a single line: the maximum score.

  7. n=3,m=3n=3, m=3. When player C acts, they may place 2,42, 4. Let xx denote the target number, where xx is a positive power of 22. Player M’s goal is to make a number xx appear on the board, while player C’s goal is to end the game before a number xx appears. Under optimal play by both sides, output the largest xx such that player M can achieve their goal.

  8. n=3,m=3n=3, m=3. When player C acts, they may place 2,42, 4. Player M’s goal is to maximize the score, and player C’s goal is to minimize the score. Under optimal play by both sides, output an integer representing the final score.

  9. n=3,m=3n=3, m=3. When player C acts, there is a 90%90\% chance to place a 22 and a 10%10\% chance to place a 44, with equal probability among all empty cells. Let xx denote the target number. Player M’s goal is to make a number at least xx appear on the board. Under player M’s optimal strategy, output one line with 99 real numbers, rounded to 22 decimal places and separated by spaces, representing the probability of achieving the target for x=2,4,8,16,32,64,128,256,512x=2, 4, 8, 16, 32, 64, 128, 256, 512.

  10. n=3,m=3n=3, m=3. When player C acts, there is a 90%90\% chance to place a 22 and a 10%10\% chance to place a 44, with equal probability among all empty cells. Player M’s goal is to maximize the score. Under player M’s optimal strategy, output one real number, rounded to the nearest integer, representing the expected score.

Although Meihong has some understanding of 20482048, she cannot solve all the problems, so she turns to you, who studies OI.

Input Format

See the problem statement.

Output Format

See the problem statement.

样例任务(无需提交):
 n=2,m=2。 玩家C行动时只可以放置2。请输出一个整数,表示棋盘上可能出现的最大数字。

16

Hint

If you are unsure about the movement rules, you can try them on the 20482048 website:

http://gabrielecirulli.github.io/2048/

by-orangebird.

Translated by ChatGPT 5