codevs——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
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
];
];
int read()
{
,f=; char ch=getchar();
; ch=getchar();}
+ch-'; ch=getchar();}
return x*f;
}
void dfs(int now)
{
)
{
;i<=n;i++)
printf("%d ",a[i]);
printf("\n");
return ;
}
;i<=n;i++)
if(!vis[i])
{
vis[i]=true;
a[now]=i;
dfs(now+);
vis[i]=false;
}
return ;
}
int main()
{
n=read();
dfs();
;
}
codevs——1294 全排列的更多相关文章
- codevs 1294 全排列 next_permuntation
#include<bits/stdc++.h> using namespace std; #define ll long long #define pi (4*atan(1.0)) #de ...
- wikioi 1294 全排列 dfs
1294 全排列 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 给出一个n, 请输出n的所有全排列 输入描述 Inpu ...
- CODE[VS] 1294 全排列
1294 全排列 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 给出一个n, 请输出n的所有全 ...
- 全排列 (codevs 1294)题解
[题目描述] 给出一个n, 请输出n的所有全排列(按字典序输出). [样例输入] 3 [样例输出] 1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1 [解题思路] 听说C++有作 ...
- Wikioi 1294 全排列
先给出链接地址:Wikioi 1294 虽然题目很短,论难度也就是个深搜,算法方面我就不多说了,而且我知道c++有个函数叫next_permutation,谁用谁知道. 代码如下: #include& ...
- codevs 1229 数字游戏(可重集的全排列)
传送门 Description Lele 最近上课的时候都很无聊,所以他发明了一个数字游戏来打发时间. 这个游戏是这样的,首先,他拿出几张纸片,分别写上0到9之间的任意数字(可重复写某个数字),然后 ...
- 【CODEVS 6384 大米兔学全排列】
·大米兔学习全排列,还有一些逆序对,还有一棵二叉索引树.· ·分析: 首先肯定不是像题目上说的那样,使用next_permutation去完成这道题,因为就算是线性的它也不能承受庞大的排列 ...
- 生成1~n的全排列
输入正整数n,输出n的全排列. 样例输入1: 3 样例输出1: 1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1 分析: 按字典序从小到大的顺序输出所有的排列. (字典序:两个序 ...
- [ CodeVS冲杯之路 ] P1294
不充钱,你怎么AC? 题目:http://codevs.cn/problem/1294/ 随手一打就是这么漂亮的全排列,想当年我初一还是初二的时候,调了1个多小时才写出来(蒟蒻一枚) 直接DFS每次枚 ...
随机推荐
- helm istio k8s docker
helm https://hub.helm.sh/ k8s https://www.kubernetes.org.cn/k8s istio 微服务 https://istio.io/
- syslog(),closelog()与openlog()--日志操作函数 (1)
文章出处:http://blog.csdn.net/xx77009833/archive/2010/07/30/5776383.aspx 为了满足某些目的,进行日志记录是很有必要的. 在典型的 LIN ...
- (1)JSTL的13个core标签库
标准标签库JSTL的全名为:Java Server Pages Standard Tag Library. (jsp standard tag library) JSTL主要提供了5大类标签库: ...
- bootstrap历练实例: 导航元素中禁用的链接
对每个 .nav class,如果添加了 .disabled class,则会创建一个灰色的链接,同时禁用了该链接的 :hover 状态, <!DOCTYPE html><html& ...
- Bootstrap 表格2
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- 调用 C 动态库
调用 C 动态库 由 王巍 (@ONEVCAT) 发布于 2015/11/04 C 是程序世界的宝库,在我们面向的设备系统中,也内置了大量的 C 动态库帮助我们完成各种任务.比如涉及到压缩的话我们很可 ...
- 使用python制作查询火车票工具
使用python脚本实现查询火车票信息的效果图如下: 实现的代码: # coding: utf-8 """命令行火车票查看器 Usage: tickets [-gdtkz ...
- (转)UIPanGestureRecognizer
UIPanGestureRecognizer是UIGestureRecognizer类的一个扩展类,其扩展类有UITapGestureRecognizer,UIPinchGestureRecogniz ...
- LeetCode(107) Binary Tree Level Order Traversal II
题目 Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from l ...
- luogu3759 [TJOI2017]不勤劳的图书管理员
分块+权值逆序对 #include <algorithm> #include <iostream> #include <cstdio> #include <c ...