http://soj.me/4495

按字典序生成字符串的全排列

直接递归:

#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的更多相关文章

  1. python 生成排列、组合以及选择

    from <python cookbook> 19.15 任务 需要对一个序列的排列(permutation).组合(combination)或选择(selection)进行迭代操作.即使 ...

  2. python迭代器Itertools

    https://docs.python.org/3.6/library/itertools.html 一无限迭代器: Iterator Arguments Results Example count( ...

  3. python实现经典算法

    1,快速排序 题目形式:手写一下快速排序算法. 题目难度:中等. 出现概率:约50%.手写快排绝对是手撕代码面试题中的百兽之王,掌握了它就是送分题,没有掌握它就是送命题. 参考代码: def quic ...

  4. Python笔试——毕业旅行问题

    毕业旅行问题 小明目前在做一份毕业旅行的规划.打算从北京出发,分别去若干个城市,然后再回到北京,每个城市之间均乘坐高铁,且每个城市只去一次.由于经费有限,希望能够通过合理的路线安排尽可能的省一些路上的 ...

  5. 【leetcode】Permutations

    题目描述: Given a collection of numbers, return all possible permutations. For example, [1,2,3] have the ...

  6. 大数求模 sicily 1020

        Search

  7. uva11630 or hdu2987 Cyclic antimonotonic permutations(构造水题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Cyclic antimonotonic permutations Time Li ...

  8. [Leetcode][Python]47: Permutations II

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 47: Permutations IIhttps://oj.leetcode. ...

  9. [Leetcode][Python]46: Permutations

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 46: Permutationshttps://leetcode.com/pr ...

随机推荐

  1. JMX rmi的一些问题

    http://hi.baidu.com/84zhu/item/79bcd5de734f1318d68ed015 http://1985wanggang.blog.163.com/blog/static ...

  2. flex lineChart中自定义datatip

    原文 http://www.giser.net/?p=776 在Flex4中使用lineChart会遇到一个bug,datatip上的背景是黑色的,造成文字看不清楚,和整体界面不协调. 那么解决这个问 ...

  3. API之IP地址查询---权威的IP地址查询接口集合

    原文地址:http://yushine.iteye.com/blog/1717586 推荐实用IP138 http://www.baidu.com/s?wd=IP&rsv_spt=1& ...

  4. C++STL_类模板举例

    #include<stdio.h> #include<typeinfo.h> template <class T1,class T2> class A{ T1 i; ...

  5. oracle check if the display variable is set

  6. Struts2 使用通配符动态请求Action

    在以前的学习中,<action>元素的配置,都是用明确的配置,其name.class等属性都是一个明确的值.其实Struts2还支持class属性和method属性使用来自name属性的通 ...

  7. Android UI ActionBar功能-启动ActionBar

    官方帮助文档:http://wear.techbrood.com/training/basics/actionbar/index.html ------------------------------ ...

  8. java实现xml文件增删改查

    java一次删除xml多个节点: 方案1.你直接改动了nodeList,这一般在做循环时是不同意直接这么做的. 你能够尝试在遍历一个list时,在循环体同一时候删除list里的内容,你会得到一个异常. ...

  9. 警告框和操作表(IOS开发)

    警告框(AlertView)时模态的,不关闭它就不能做其它事情,所以不是下面几种情况不应该随便使用. 1.应用不能继续执行. 如内存不足,没有网络.一般仅仅须要一个button. 2.询问还有一个解决 ...

  10. C#语言小结

    数据类型--变量与常量--运算符与表达式--语句(if,for)--数组--函数--结构体 一.数据类型:(一)内建类型整型(int short long byte uint ushort ulong ...