CODE[VS] 1294 全排列
给出一个n, 请输出n的所有全排列
读入仅一个整数n (1<=n<=10)
一共n!行,每行n个用空格隔开的数,表示n的一个全排列。并且按全排列的字典序输出。
3
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
这个题目个人是用深搜解决的,貌似用STL的话就很简单了
就是先搜索那个数放第一,再递归放后面的数
这题目竟然卡了printf,scanf,我还能说什么
#include <iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int visit[];
int b[];
int n;
void dfs(int i)
{
if(i>n)
{
for(int j=;j<=n;j++)
{
if(j!=n)
printf("%d ",b[j]);
else printf("%d\n",b[j]);
}
return;
}
else
{
for(int j=;j<=n;j++)
{
if(!visit[j])
{
b[i] = j;
visit[j] = ;
dfs(i+);
visit[j] = ;
}
}
}
}
int main()
{
scanf("%d",&n);
memset(visit,,sizeof(visit));
dfs();
return ;
}
CODE[VS] 1294 全排列的更多相关文章
- wikioi 1294 全排列 dfs
1294 全排列 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 给出一个n, 请输出n的所有全排列 输入描述 Inpu ...
- codevs——1294 全排列
1294 全排列 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 给出一个n, 请输出n的所有全 ...
- codevs 1294 全排列 next_permuntation
#include<bits/stdc++.h> using namespace std; #define ll long long #define pi (4*atan(1.0)) #de ...
- Wikioi 1294 全排列
先给出链接地址:Wikioi 1294 虽然题目很短,论难度也就是个深搜,算法方面我就不多说了,而且我知道c++有个函数叫next_permutation,谁用谁知道. 代码如下: #include& ...
- LeetCode 中等题解(4)
40 组合总和 II Question 给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合. candidates ...
- 全排列 (codevs 1294)题解
[题目描述] 给出一个n, 请输出n的所有全排列(按字典序输出). [样例输入] 3 [样例输出] 1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1 [解题思路] 听说C++有作 ...
- [LeetCode] Palindrome Permutation 回文全排列
Given a string, determine if a permutation of the string could form a palindrome. For example," ...
- 组合数学 + STL --- 利用STL生成全排列
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- 28. 字符串的全排列之第2篇[string permutation with repeating chars]
[本文链接] http://www.cnblogs.com/hellogiser/p/string-permutation-with-repeating-chars.html [题目] 输入一个字符串 ...
随机推荐
- WTM 构建DotNetCore开源生态,坐而论道不如起而行之
作为一个8岁开始学习编程,至今40岁的老程序员,这辈子使用过无数种语言,从basic开始,到pascal, C, C++,到后来的 java, c#,perl,php,再到现在流行的python. 小 ...
- 无法正常卸载pr
控制面板找不到pr和ps,根本无法卸载,我试过官方工具没用,也试过ccleaner,也检测不到?
- WIZnet-io6Library下载及使用
概观 io6Library是一个IPv6集成库,可以轻松集成和管理使用WIZnet硬连线双TCP / IP堆栈控制器(WIZCHIP)产品系列的用户应用程序. io6Library用于管理依赖于用户特 ...
- 使用pandoc简单教程
使用pandoc作为过滤器 {#step-4-using-pandoc-as-a-filter} 类型 pandoc 并按Enter键.你应该看到光标就在那里,等着你输入一些东西.输入: Hello ...
- Django-channels 实现WebSocket实例
引入 先安装三个模块 pip install channels pip install channels_redis pip install pywin32 创建一个Django项目和一个app 项目 ...
- Python爬虫(一)抓取指定的页面
(以下是在windows环境下的操作,python版本为3) 1.urllib库介绍 官方文档上的解释是: urllib is a package that collects several modu ...
- Servlet 获取 数组id进行批量删除
把获取的复选框选中的 id(一般来说都是根据id 进行批量删除的) 从jsp页面 传值到Servlet中 jsp点击事件中: var array=[]; //先声明一个数组变量 var ids=$( ...
- Suring开发集成部署时问题记录
前言 开发时一定要用管理员模式打开VS或者VSCODE进行开发,同时不要在nuget上直接下载,要去github上下载源代码调试.第一方便调试,第二Surging迭代较快,nuget版本往往不是最新的 ...
- xgboost保险赔偿预测
XGBoost解决xgboost保险赔偿预测 import xgboost as xgb import pandas as pd import numpy as np import pickle im ...
- Leetcode之深度优先搜索(DFS)专题-473. 火柴拼正方形(Matchsticks to Square)
Leetcode之深度优先搜索(DFS)专题-473. 火柴拼正方形(Matchsticks to Square) 深度优先搜索的解题详细介绍,点击 还记得童话<卖火柴的小女孩>吗?现在, ...