Sicily 4495. Print permutations
按字典序生成字符串的全排列
直接递归:
#include <iostream>
#include <string>
#include <cstring> using namespace std; int len;
bool ever[9];
string str; void permutation(string cur)
{
if(cur.size() == len)
{
cout<<cur<<endl;
return ;
}
for(int i=0;i<len;++i)
{
if(!ever[i])
{
ever[i] = 1;
permutation(cur + str[i]);
ever[i] = 0;
}
}
} int main()
{
while(cin>>str)
{
memset(ever,0,sizeof(ever));
len = str.size();
permutation("");
}
return 0;
}
Sicily 4495. Print permutations的更多相关文章
- python 生成排列、组合以及选择
from <python cookbook> 19.15 任务 需要对一个序列的排列(permutation).组合(combination)或选择(selection)进行迭代操作.即使 ...
- python迭代器Itertools
https://docs.python.org/3.6/library/itertools.html 一无限迭代器: Iterator Arguments Results Example count( ...
- python实现经典算法
1,快速排序 题目形式:手写一下快速排序算法. 题目难度:中等. 出现概率:约50%.手写快排绝对是手撕代码面试题中的百兽之王,掌握了它就是送分题,没有掌握它就是送命题. 参考代码: def quic ...
- Python笔试——毕业旅行问题
毕业旅行问题 小明目前在做一份毕业旅行的规划.打算从北京出发,分别去若干个城市,然后再回到北京,每个城市之间均乘坐高铁,且每个城市只去一次.由于经费有限,希望能够通过合理的路线安排尽可能的省一些路上的 ...
- 【leetcode】Permutations
题目描述: Given a collection of numbers, return all possible permutations. For example, [1,2,3] have the ...
- 大数求模 sicily 1020
Search
- uva11630 or hdu2987 Cyclic antimonotonic permutations(构造水题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Cyclic antimonotonic permutations Time Li ...
- [Leetcode][Python]47: Permutations II
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 47: Permutations IIhttps://oj.leetcode. ...
- [Leetcode][Python]46: Permutations
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 46: Permutationshttps://leetcode.com/pr ...
随机推荐
- JS中如何使用Cookie
1.关于JS设置Cookie的说明 在Javascript脚本里,一个cookie 实际就是一个字符串属性.当你读取cookie的值时,就得到一个字符串,里面当前WEB页使用的所有cookies的名称 ...
- Div布局案例
通常看到这个页面,会想到它是有几块组成的. 第一块,分销佣金. 第二块,包括代言.商品.二维码 其中代言又是左右结构. 于是乎基本的div结构就出来了. <div class="row ...
- nodejs递归创建目录,同步和异步方法
nodejs递归创建目录,同步和异步方法.在官方API中只提供了最基本的方法,只能创建单级目录,如果要创建一个多级的目录(./aaa/bbb/ccc)就只能一级一级的创建,感觉不是很方便,因此简单写了 ...
- nginx启动关闭
[root@localhost sbin]# ./nginx -s reload [root@localhost sbin]# ./nginx -s stop [root@localhost sbin ...
- 系统学习Linux的11点建议
一.从基础开始 常常有些朋友在 Linux 论坛问一些问题,不过,其中大多数的问题都是很基础的.例如为什么我使用一个命令的时候,系统告诉我找不到该目录,我要如何限制使用者的权限等问题,这些问题其实都不 ...
- 两个有序list合并
package 剑指office; import java.util.ArrayList; import java.util.List; public class ListMerge { /** * ...
- mysql存储过程和触发器的应用
***********[mysql 存储过程和触发器 -- 别安驹]********************* 1.什么情况下使用存储过程? 完成一些比较麻烦的逻辑,比如多表在mysql端的cpu很空 ...
- kafka 使用、介绍
kafka 是一个消息系统, 具体资料可以参考官网: BrokerKafka集群包含一个或多个服务器,这种服务器被称为broker Topic每条发布到Kafka集群的消息都有一个类别,这个类别被称 ...
- js 和 jsp关系
http://stackoverflow.com/questions/11718063/use-javascript-or-jquery-inside-a-cif-statement 纠结了半天的问题
- QF——OC中的KVC,KVO
KVC: (Key Value Coding) 键值编码 所谓KVC,其实就是不通过set和get方法访问对象属性,而是通过属性名字符串动态的去读取属性.KVC其实也是OC反射机制的一种运用. 之所以 ...