uva 11129 An antiarithmetic permutation
A permutation of n+1 is a bijective function of the initial n+1 natural numbers: 0, 1, ...
n. A permutation p is called antiarithmetic if there is no...
分类:
其他好文 时间:
2015-03-07 15:47:10
阅读次数:
132
生成字典续序列。
//
// main.cpp
// 10098_1
//
// Created by Fangpin on 15/3/7.
// Copyright (c) 2015年 FangPin. All rights reserved.
//
#include
#include
#include
#include
using namespace std;
char s...
分类:
其他好文 时间:
2015-03-07 15:45:37
阅读次数:
141
https://oj.leetcode.com/problems/next-permutation/Implement next permutation, which rearranges numbers into the lexicographically next greater permuta...
分类:
其他好文 时间:
2015-03-06 22:06:43
阅读次数:
151
代码: 1 class Solution { 2 public: 3 void nextPermutation(vector &num) { 4 5 const auto first = num.begin(); 6 const auto last = nu...
分类:
其他好文 时间:
2015-03-04 16:00:16
阅读次数:
106
题意:给2~10个不同的数字,要求把这些数字分成两堆,每一堆任意组合成一个数(开头不能为0),求两个数差的最小值。
思路:数据很小,直接暴力枚举所有情况,并且很容易想到,要使差最小则这两个数的位数应该尽量相等;枚举排列时用到了next_permutation函数。...
分类:
其他好文 时间:
2015-03-03 22:16:38
阅读次数:
265
题意:给定字符串的长度,以及汉明距离,求所有和全0字符串汉明距离为给定值的等长字符串,升序输出。
思路:长度n,汉明距离h,相当于n-h个0和h个1的序列,进行枚举全排列。
感觉这几题都是排列和子集相关的枚举额,推荐的题目没有其他的枚举或暴力求解的吗?感觉不是很好额~
Code:
#include
#include
void print_permutation(int n,int *P,...
分类:
其他好文 时间:
2015-02-27 15:15:16
阅读次数:
160
题意:输出一个排列的后继排列,如果是最大的降序排列,则输出没有后继。
思路:调用STL中的next_permutation()函数即可。不过这个函数在求后继时是一个循环状态,即全升序是全降序的后继,循环回来了。所以在调用之前判断一下是否为全降序序列即可。 感觉用这个函数没什么技术含量,有时间用纯C写一个。
Code:
#include
#include
#include
usi...
分类:
其他好文 时间:
2015-02-27 13:34:29
阅读次数:
113
输入正数n,按字典序从小到大的顺序输出n个数的所有排列。两个序列的字典序大小关系等价于从头开始第一个不相同位置处的大小关系。
一、生成1~n的排列
思路:
void print_permutation(序列A,集合S)
{
if ( S 为空 ) 输出序列 A;
else 按照从小到大的顺序依次考虑 S 的每个元素 v
{
prin...
分类:
其他好文 时间:
2015-02-27 00:21:19
阅读次数:
174
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possibl...
分类:
其他好文 时间:
2015-02-25 11:34:39
阅读次数:
160
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.
If such arrangement is not possible, it must rearrange it as the lowest possible...
分类:
其他好文 时间:
2015-02-24 21:04:51
阅读次数:
218