Forgot password?
 Register account
View 8588|Reply 11

[组合] 移动路线问题

[Copy link]

83

Threads

434

Posts

5419

Credits

Credits
5419

Show all posts

tommywong Posted 2014-2-1 08:11 |Read mode
Last edited by hbghlyj 2025-5-25 19:15在4×6矩形框内,取对角线上A,B两点
问:一,从A移动到B有多少条不重复的路线?(每条路线经过的节点不能重复)
二,若将图中的红点去掉,则表示“此路不通”,需要绕道而行。现在要使得从A到B的路线少于原先的二分之一,则至少要去掉几个红点?为什么?

图一:未去掉红点

图二:已去掉部分红点

3153

Threads

7906

Posts

610K

Credits

Credits
64096
QQ

Show all posts

hbghlyj Posted 2025-5-24 19:09
用动态规划来解决。但时间复杂度关于$\min(n,m)$为指数级。

411

Threads

1619

Posts

110K

Credits

Credits
11813

Show all posts

abababa Posted 2025-5-25 16:24
这个是不是考虑减少的路线就行了,比如一个点$(x,y)$,通过这个点的路线应该是有$\binom{x+y}{x}\cdot\binom{10-(x+y)}{6-x}$条路线。然后算出这个的最大值是多少,去掉这个最大值的点,就能去掉最多的线路。
但是我觉得把点A或点B去掉,不就直接满足条件了吗,这行不行呢

Comment

对的,它是 4 x 6 而不是 5 x 6 网格,我已帮作者改正。  Posted 2025-5-25 19:47

3153

Threads

7906

Posts

610K

Credits

Credits
64096
QQ

Show all posts

hbghlyj Posted 2025-5-25 18:59
abababa wrote at 2025-5-25 09:24
把点A或点B去掉,不就直接满足条件了吗
去掉任意$n$个点后,从A到B的路线都少于原先的1/2,则$n$至少为?

411

Threads

1619

Posts

110K

Credits

Credits
11813

Show all posts

abababa Posted 2025-5-25 19:09
hbghlyj 发表于 2025-5-25 18:59
去掉任意$n$个点后,从A到B的路线都少于原先的1/2,则$n$至少为?
任意n个就是求那个乘积的最小值吧,不够就一直往上加,直到达到1/2。

4

Threads

139

Posts

2198

Credits

Credits
2198

Show all posts

Aluminiumor Posted 2025-5-25 19:28
abababa 发表于 2025-5-25 16:24
通过这个点的路线应该是有$\binom{x+y}{x}\cdot\binom{10-(x+y)}{6-x}$条
你这样考虑对应的是只能向上和向右走,但题目没有限定
Wir müssen wissen, wir werden wissen.

4

Threads

139

Posts

2198

Credits

Credits
2198

Show all posts

Aluminiumor Posted 2025-5-25 19:30
问题并没有限制只能向上和向右走,那么问题一的答案也没那么简单(不是 $C_{10}^4$)
Wir müssen wissen, wir werden wissen.

411

Threads

1619

Posts

110K

Credits

Credits
11813

Show all posts

abababa Posted 2025-5-25 19:51
Aluminiumor 发表于 2025-5-25 19:30
问题并没有限制只能向上和向右走,那么问题一的答案也没那么简单(不是 $C_{10}^4$) ...
我觉得应该有限制才行吧,如果不限制的话,那就在一小段里多次重复,重复的次数不同,就算不同的路线了,这就没意义了。

4

Threads

139

Posts

2198

Credits

Credits
2198

Show all posts

Aluminiumor Posted 2025-5-25 19:53
abababa 发表于 2025-5-25 19:51
我觉得应该有限制才行吧,如果不限制的话,那就在一小段里多次重复,重复的次数不同,就算不同的路线了, ...
题目有限制不能重复经过节点
Wir müssen wissen, wir werden wissen.

4

Threads

139

Posts

2198

Credits

Credits
2198

Show all posts

Aluminiumor Posted 2025-5-25 19:59
  1. def count_paths():
  2.     max_x = 6
  3.     max_y = 4
  4.     start = (0, 0)
  5.     end = (6, 4)
  6.     # 记录哪些点已经被访问过
  7.     visited = [[False for _ in range(max_y + 1)] for _ in range(max_x + 1)]
  8.     # 检查点是否在网格内且未被访问
  9.     def is_valid(x, y):
  10.         return 0 <= x <= max_x and 0 <= y <= max_y and not visited[x][y]
  11.     directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
  12.     def backtrack(current_x, current_y):
  13.         if (current_x, current_y) == end:
  14.             return 1
  15.         count = 0
  16.         for dx, dy in directions:
  17.             next_x, next_y = current_x + dx, current_y + dy
  18.             if is_valid(next_x, next_y):
  19.                 visited[next_x][next_y] = True
  20.                 count += backtrack(next_x, next_y)
  21.                 visited[next_x][next_y] = False
  22.         return count
  23.     visited[start[0]][start[1]] = True
  24.     total_paths = backtrack(start[0], start[1])
  25.     return total_paths
  26. print(count_paths())
Copy the Code
写了一段 Python 代码,输出 752061

Comment

事实上,去除(3,2)这个点后,路线数只剩下 141296  Posted 2025-5-25 20:13
Wir müssen wissen, wir werden wissen.

Mobile version|Discuz Math Forum

2025-6-5 01:08 GMT+8

Powered by Discuz!

× Quick Reply To Top Edit