深搜   注意与STL模版的去重函数唯一的区别就是有去重。

#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
int len;
],ss[];
];
bool cmp(char a,char b)
{
    double t1=a,t2=b;
    if(a>='A'&&a<='Z') t1+=31.5; //神来之笔,对于cmp的神级处理
    if(t2>='A'&&t2<='Z') t2+=31.5;
    return t1<t2;
}

void dfs(int x)
{
    if(x==len)
    {
        ;i<len;++i)
        printf("%c",ch[i]);
        printf("\n");
    }
    else
    {
        ;i<len;i++)  //以任意顺序开头
        {
            if(!visted[i])
            {
                ch[x]=ss[i];
                visted[i]=;
                dfs(x+);
                visted[i]=; //另一进程需要更新dfs之前的值
                <len&&ss[i+]==ss[i])i++;  //去重
            }
        }
    }
}

int main()
{
    //freopen("in.txt","r",stdin);
    int cas;
    scanf("%d",&cas);
    while(cas--)
    {
        memset(visted,,sizeof(visted));
        scanf("%s",ss);
        len=strlen(ss);
        sort(ss,ss+len,cmp);
        dfs();
    }
    ;
}

网上看到的一段代码:

用的是STL的库函数next_permutation全排列

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

bool cmp(char a,char b)
{
if(tolower(a)==tolower(b))
return a<b;
else
return tolower(a)<tolower(b);
}

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        string str;
        cin>>str;
        sort(str.begin(),str.end(),cmp);
        do
        {
            cout<<str<<endl;
        }
        while(next_permutation(str.begin(),str.end(),cmp));
    }
    ;
}

【字母全排列】 poj 1256的更多相关文章

  1. poj 1256 按一定顺序输出全排列(next_permutation)

    Sample Input 3aAbabcacbaSample Output AabAbaaAbabAbAabaAabcacbbacbcacabcbaaabcaacbabacabcaacabacbaba ...

  2. POJ 1256.Anagram

    2015-06-04 问题简述: 输出一串字符的全排列,顺序不同于一般的字母序,而是 A<a<B<b......<Z<z.所以应该重写一个比较函数. 原题链接:http: ...

  3. poj 1256 Anagram(dfs)

    题目链接:http://poj.org/problem?id=1256 思路分析:该题为含有重复元素的全排列问题:由于题目中字符长度较小,采用暴力法解决. 代码如下: #include <ios ...

  4. 简单的字母全排列问题—递归法和STL法

    问题描述:求全由小写字母组成的不超过200个字符序列的全排列 如输入序列bbjd,排列结果为: bbdj bbjd bdbj bdjb bjbd bjdb dbbj dbjb djbb jbbd jb ...

  5. next_permutation,POJ(1256)

    题目链接:http://poj.org/problem?id=1256 解题报告: 1.sort函数是按照ASC11码排序,而这里是按照 'A'<'a'<'B'<'b'<... ...

  6. poj 1256 Anagram—next_permutation的神奇应用

    题意:给你一条字符串,让你输出字符串中字符的全排列,输出的顺序要按它给的奇葩的字典序. 题解:要输出全排列,暴力dfs可以过,但要注意题目的字典序以及相同字符的情况.如果用next_permutati ...

  7. POJ 1256:Anagram

    Anagram Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18393 Accepted: 7484 Description ...

  8. WLLCM这五个字母全排列数目

           经过训练的话一眼看出来是5!/2!:我想的是先排WLCM那么是4!,5个位置,由于L左右两边的位置其实是一样的(再插入的还是L),索以结果是4*4!,这样重复了,看下图.         ...

  9. POJ 1256

    //#include "stdafx.h" #include <stdio.h> #include <string.h> #define N_MAX 14 ...

随机推荐

  1. UITableView控制头部View

    首先我们先集成一个UIView做一个自己的View #import <UIKit/UIKit.h> @interface MyView : UIView @property (nonato ...

  2. FZU 1502 Letter Deletion(DP)

    Description You are given two words (each word consists of upper-case English letters). Try to delet ...

  3. HDU 1564 Play a game

    Description New Year is Coming! ailyanlu is very happy today! and he is playing a chessboard game wi ...

  4. 小心DLL链接静态库时的内存错误

    本文转自http://www.bennychen.cn/2010/09/%E5%B0%8F%E5%BF%83dll%E9%93%BE%E6%8E%A5%E9%9D%99%E6%80%81%E5%BA% ...

  5. 关于解决“No matching provisioning profiles found”问题-ios

    xcode7之后真机调试就可以不需要调试证书了,但其中也会遇到一些问题令人挠头搔耳.记录下来是给自己提供方便,也为初遇到此问题的人提供解答,利人利己的事情我做!   上图: 图一 本人有一种视警号为e ...

  6. ECOS-Ecstore mongodb大数据 读写效率优化

    转自同功BBS 拆表存取kv <?php /* 经过拆变优化的ECStore mongodb 类 base/lib/kvstore/mongodb.php*/ class base_kvstor ...

  7. 【python问题系列--3】TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'

    p0V,p1V,pSpam=trainNBO(array[trainMat],array(trainClasses)) 改为: p0V,p1V,pSpam=trainNBO(array(trainMa ...

  8. SEO优化技巧总结

    SEO优化技巧总结 一:了解搜索引擎 基础知识 搜索引擎:由蜘蛛程序沿着链接爬行和抓取网上的大量页面,存进数据库,经过预处理,用户在搜索框 输入关键词后,搜索引擎排序从数据库中挑选出符合搜索关键词要求 ...

  9. sql语句的使用;

    1.导出数据库的语句: mysqldump -u root -p shop > d:\shop.sql

  10. Django 基础知识

    Django Models django 本身提供了非常强大易使用的ORM组件,并且支持多种数据库,如sqllite,mysql,progressSql,Oracle等,当然最常用的搭配还是mysql ...