题目链接:http://poj.org/problem?id=1731

思路分析:含有重复元素的全排列问题;元素个数为200个,采用暴力枚举法。

代码如下:

#include <iostream>
#include <algorithm>
using namespace std; const int MAX_N = + ;
void PrintPermu( int n, char P[], char A[], int cur )
{
int i, j; if ( cur == n )
{
for ( i = ; i < n; ++i )
cout << A[i];
cout << endl;
}
else
{
for ( int i = ; i < n; ++i )
{
if ( i == || P[i] != P[i-] )
{
int c1 = , c2 = ; for ( j = ; j < cur; ++j )
if ( A[j] == P[i] ) c1++;
for ( j = ; j < n; ++j )
if ( P[i] == P[j] ) c2++; if ( c1 < c2 )
{
A[cur] = P[i];
PrintPermu( n, P, A, cur + );
}
}
}
}
} int main()
{
char P[MAX_N], A[MAX_N]; cin >> P;
sort( P, P + strlen(P) );
PrintPermu( strlen(P), P, A, );
return ;
}

poj 1731 Orders(暴力)的更多相关文章

  1. poj 1731 Orders

    http://poj.org/problem?id=1731 Orders Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9 ...

  2. POJ 1731 Orders(STL运用)

    题目地址:POJ 1731 这题能够直接用STL函数做,非常轻松..next_permutation函数非常给力.. 代码例如以下: #include <algorithm> #inclu ...

  3. Orders POJ - 1731

    The stores manager has sorted all kinds of goods in an alphabetical order of their labels. All the k ...

  4. POJ 1731:Orders

    Orders Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9940   Accepted: 6048 Descriptio ...

  5. poj 2363 Blocks(暴力)

    题目链接:http://poj.org/problem?id=2363 思路分析:由于数据较小,采用暴力搜索法.假设对于矩形边长 1 <= a <= b <= c <= N; ...

  6. POJ 2029 DP || 暴力

    在大矩形中找一个小矩形 使小矩形包括的*最多 暴力或者DP  水题 暴力: #include "stdio.h" #include "string.h" int ...

  7. POJ 2912 Rochambeau(暴力)+【带权并查集】

    <题目链接> 题目大意: n个人进行m轮剪刀石头布游戏(0<n<=500,0<=m<=2000),接下来m行形如x, y, ch的输入,ch='='表示x, y平局 ...

  8. POJ 2912 - Rochambeau - [暴力枚举+带权并查集]

    题目链接:http://poj.org/problem?id=2912 Time Limit: 5000MS Memory Limit: 65536K Description N children a ...

  9. POJ 3414 Pots 暴力,bfs 难度:1

    http://poj.org/problem?id=3414 记录瓶子状态,广度优先搜索即可 #include <cstdio> #include <cstring> #inc ...

随机推荐

  1. SqlServer 2015修改表时出现“save changes is not permitted…”的解决方法

    使用SqlServer 2015的过程中,会出现如下情况: 在修改完表字段名或是类型后点击保存时会弹出一个对话框,且无法保存已做的修改.对话框内容大致如下: Saving changes is not ...

  2. centos7 环境搭建

    centos7 环境搭建    CentOS-7-x86_64-DVD-1511.iso    vmware121. 安装    使用iso安装系统:2. 修改yum源到光盘        先把光盘C ...

  3. USB数据流模型

    USB数据流模型 <<USB Specification11>> << USB Specification20>> << Linux Dev ...

  4. Apache与Nginx网络模型

    Nginx的高并发得益于其采用了epoll模型,与传统的服务器程序架构不同,epoll是linux内核2.6以后才出现的.下面通过比较Apache和Nginx工作原理来比较. 传统Apache都是多进 ...

  5. A Byte of Python 笔记(2)基本概念:数、字符串、转义符、变量、标识符命名、数据类型、对象

    第4章 基本概念 字面意义上的常量 如5.1.23.9.23e-3,或者 'This is a string'."It's a string!" 字符串等 常量,不能改变它的值 数 ...

  6. 解决python2.7.9以下版本requests访问https的问题

    在python2.7.9以下版本requests访问https连接后,总会报一些关于SSL warning. 解决法子可以参考:https://urllib3.readthedocs.io/en/la ...

  7. python自学笔记(六)二进制与位移

    一.二进制 a = 1 bin(a)-->ob1  #python内置方法 ob 表示二进整型制格式 二.难缠符号 1.位移二进制的位 >> 右位移,想象成 切肉切去最后一位 例如 ...

  8. ASP.NET jQuery 随笔 使用allValidator插件简单实现客户端验证功能

    首先放出该插件的下载地址:http://pan.baidu.com/s/1Aa3yD,里面有帮助文档,详细了解可以自行下载学习,本章只讲解一些基本的验证功能,页面代码如下: <%@ Page L ...

  9. Json.Net系列教程 1.Json.Net介绍及实例

    原文 Json.Net系列教程 1.Json.Net介绍及实例 本系列教程假设读者已经对Json有一定的了解,关于Json在这里不多说.本系列教程希望能对读者开发涉及到Json的.Net项目有一定的帮 ...

  10. 共享内存操作类(C#源码)

    原文 http://blog.csdn.net/yefanqiu/article/details/1717458 VC++的共享内存操作代码实现起来相对比较容易,但是用C#语言来实现,就有一定难度,由 ...