首页
题库
面试
求职
学习
竞赛
More+
所有博客
搜索面经/职位/试题/公司
搜索
我要招人
去企业版
登录 / 注册
首页
>
试题广场
>
圆环回原点
[编程题]圆环回原点
热度指数:3671
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 256M,其他语言512M
算法知识视频讲解
圆环上有 10 个点,编号 0~9 。从 0 出发,每次可以顺时针或逆时针走一格,请问一共走且仅走 n 步回到原点的方法有多少种。
数据范围:
,由于答案可能会非常大,所以请对答案对
取模
示例1
输入
3
输出
0
说明
无论如何也不可能走 3 步回到原点
示例2
输入
2
输出
2
说明
可能的方案有 0->1->0, 0->9->0
马上挑战
算法知识视频讲解
提交运行
算法知识视频讲解
添加笔记
求解答(0)
邀请回答
收藏(46)
分享
纠错
提交结果有问题?
1个回答
3篇题解
开通博客
newcoderk
发表于 2022-06-18 10:42:38
dp定义 dp[i][j]表示走i步到达编号为j的节点共有多少中方法 状态转移 dp[i][j] = dp[i-1][j-1] (i-1步走到j左边的方法数) + dp[i-1][j+1](i-1步走到j右边的方法数) 注意: 上边为了方便理解,没有处理j-1和j+1的越界问题,在下边代码中体现 b
展开全文
姐姐的遮阳伞
发表于 2022-04-10 16:41:13
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return
展开全文
17c89
发表于 2024-07-23 16:57:08
import java.util.*; /** * NC311 圆环回原点 * @author d3y1 */ public class Solution { private final int MOD = 1000000007; /** * 代码中的类名、方法名
展开全文
问题信息
动态规划
难度:
1条回答
46收藏
2575浏览
热门推荐
通过挑战的用户
查看代码
NumberP...
2023-03-04 20:00:19
做选择最难
2023-03-03 10:43:46
0xC7
2023-02-24 15:11:42
cs_cyj
2023-02-23 17:23:31
相信光你就是光
2023-02-23 09:43:22
相关试题
以下关于 HTTP/2 的说法,哪...
网络基础
评论
(1)
翻转01
字符串
饿了么
双指针
评论
(1)
数组同构
堆
贪心
位运算
评论
(1)
在进行计算流体力学(CFD)仿真时...
流体力学
评论
(1)
如果在系统设计中错误地将二叉最小堆...
堆
评论
(2)
圆环回原点
扫描二维码,关注牛客网
意见反馈
下载牛客APP,随时随地刷题
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ public int circle (int n) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ int circle(int n) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param n int整型 # @return int整型 # class Solution: def circle(self , n ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ public int circle (int n) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ function circle( n ) { // write code here } module.exports = { circle : circle };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param n int整型 # @return int整型 # class Solution: def circle(self , n: int) -> int: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ func circle( n int ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ int circle(int n ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param n int整型 # @return int整型 # class Solution def circle(n) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ def circle(n: Int): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ fun circle(n: Int): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ public int circle (int n) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ export function circle(n: number): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ func circle ( _ n: Int) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ pub fn circle(&self, n: i32) -> i32 { // write code here } }
3
0
2
2