题目要求
题目链接
其实应该用DFS啦,打表还是免了, 9 ! 9! 9!警告。
怎么搜呢?一个boolean数组+一个int数组,int数组按顺序存每一位的数值,boolean数组的index对应实际数值,而true表示已被使用。
一旦搜到的used[i]是true,那就剪枝,确实没有搜的必要了。
AC代码(Java语言描述)import java.util.Scanner;
public class Main {
private static StringBuilder result = new StringBuilder();
private static int num;
private static int[] sequence;
private static boolean[] used;
private static void dfs(int k) {
if (k == num) {
for (int j = 1; j
关注
打赏
热门博文
- 【Linux】Ubuntu20.04安装和卸载MySQL8
- 【Linux】Ubuntu 20.04 报错 curl: (23) Failure writing output to destination 的解决方法
- 【Java】JUnit 4.13.2 警告 ‘assertEquals(double, double)‘ is deprecated 的解决方法
- 【JavaScript】处理 @parcel/transformer-js: Browser scripts cannot have imports or exports.
- 【Node.js】Windows环境安装配置NVM和Node.js
- 【Python】处理TypeError: Plain typing.NoReturn is not valid as type argument
- 【Python】Matplotlib可视化50例
- 【C语言】C语言修改MySQL数据库
- 【Java】从默认包导入类和对象报错的解决方法
- 【Java】panel.getGraphics()报错空指针异常的解决方法