牛客题霸-算法篇
N皇后问题
相似的企业真题
时间限制:C/C++ 2秒,其他语言4秒
空间限制:C/C++ 256M,其他语言512M
热度指数:3163
本题知识点:
回溯
算法知识视频讲解
校招时部分企业笔试将禁止编程题跳出页面,为提前适应,练习时请使用在线自测,而非本地IDE。
题目描述
皇后问题是指在
的棋盘上要摆
个皇后,
要求:任何两个皇后不同行,不同列也不再同一条斜线上,
求给一个整数
,返回
皇后的摆法数。
示例1
输入
复制
1
1
返回值
复制
1
1
示例2
输入
复制
8
8
返回值
复制
92
92
备注:
上一题
下一题
登录
/
注册
我的提交
编辑器加载中...
import java.util.*; public class Solution { /** * * @param n int整型 the n * @return int整型 */ public int Nqueen (int n) { // write code here } }
class Solution { public: /** * * @param n int整型 the n * @return int整型 */ int Nqueen(int n) { // write code here } };
# # # @param n int整型 the n # @return int整型 # class Solution: def Nqueen(self , n ): # write code here
/** * * @param n int整型 the n * @return int整型 */ function Nqueen( n ) { // write code here } module.exports = { Nqueen : Nqueen };
# # # @param n int整型 the n # @return int整型 # class Solution: def Nqueen(self , n ): # write code here
package main /** * * @param n int整型 the n * @return int整型 */ func Nqueen( n int ) int { // write code here }
/** * * @param n int整型 the n * @return int整型 */ int Nqueen(int n ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # @param n int整型 the n # @return int整型 # class Solution def Nqueen(n) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param n int整型 the n * @return int整型 */ def Nqueen(n: Int): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param n int整型 the n * @return int整型 */ fun Nqueen(n: Int): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param n int整型 the n * @return int整型 */ public int Nqueen (int n) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param n int整型 the n * @return int整型 */ export function Nqueen(n: number): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param n int整型 the n * @return int整型 */ func Nqueen ( _ n: Int) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param n int整型 the n * @return int整型 */ pub fn Nqueen(&self, n: i32) -> i32 { // write code here } }
1
1
8
92