题目链接: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. IOS学习之蓝牙4.0 BLE

    IOS学习也一段时间了,该上点干货了.前段时间研究了一下IOS蓝牙通讯相关的东西,把研究的一个成果给大家分享一下. 一 项目背景 简单介绍一下做的东西,设备是一个金融刷卡器,通过蓝牙与iphone手机 ...

  2. 搭建Myeclipse下Java Web开发环境

    1.准备 先下载软件:Myeclipse:http://www.xiazaiba.com/html/23858.html tomcat:http://files.cnblogs.com/files/l ...

  3. objective-C学习笔记(七) 字符串处理

    字符串NSString NSString 是一个Unicode编码,16位字符的字符序列. NSString 是一个类,拷贝时需要注意. 初始化方法:字面量初始化.初始化器.工厂方法. NSStrin ...

  4. centos6.5安装pysider遇见的坑

    一.服务器自带pyhon2.7.9 安装pip, # yum -y install python-devel python-setuptool wget http://pypi.python.org/ ...

  5. app微信支付服务器端php demo

    class Wxpay { /* 配置参数 */ private $config = array( 'appid' => "wxc92b12277f277355", /*微信 ...

  6. bzoj 1046 : [HAOI2007]上升序列 dp

    题目链接 1046: [HAOI2007]上升序列 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3620  Solved: 1236[Submit] ...

  7. strlen源码剖析

      学习高效编程的有效途径之一就是阅读高手写的源代码,CRT(C/C++ Runtime Library)作为底层的函数库,实现必然高效.恰好手中就有glibc和VC的CRT源代码,于是挑了一个相对简 ...

  8. CI URL 辅助函数 url helper

    URL 辅助函数文件包含一些在处理 URL 中很有用的函数 加载辅助函数 本辅助函数通过如下代码加载: $this->load->helper('url'); 可用函数如下: site_u ...

  9. 基于Visual C++2013拆解世界五百强面试题--题10-找出N个数种最大的K个数

    有一亿个整数,请找出最大的 1000 个,要求时间越短越好, 空间占用越好越好. 如果不考虑时间效率,很容易想到解决方法,我们只需存储前一千个数, 然后依次读入后面的数和这一千个数组比较,替换其中比较 ...

  10. HDU 2717 Catch That Cow

    简单的广搜: #include <cstdio> #include <queue> using namespace std; ],step[]; int n,start,end ...