约瑟夫问题(动态规划解法)

博客介绍了约瑟夫问题的动态规划求解方法,通过分析不同循环次数下的规律,得出公式,并利用该公式通过循环计算出最终答案,提高了效率,避免了m*n的复杂度,展示了算法的魅力。
摘要由CSDN通过智能技术生成

Josephus problem solution with o(n)

1.Description

People are standing in a circle waiting to be executed. Counting begins at a specified point in the circle and proceeds around the circle in a specified direction. After a specified number of people are skipped, the next person is executed. The procedure is repeated with the remaining people, starting with the next person, going in the same direction and skipping the same number of people, until only one person remains, and is freed.

2.Introduction

We have seen this kind of problems before. You can stimulate the whole process to get the answer you want. But its time cost is large, which holds a m*n complexity. This method can be accepted when n and m are accepted small, but fail to handle those situations when n or m is quite large. Thus, today let’s introduce a new method with a complexit

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值