我如何获得XPY的所有排列? [英] How do I get all permutations of xPy?

查看:160
本文介绍了我如何获得XPY的所有排列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算尺寸的Y一组尺寸X的就是说,如果我有(1,2,3)的所有排列和大小要2的所有排列,3P2,这将是(1, 2)(1,3)(2,1)(2,3)(3,1)(3,2)

I'd like to calculate all the permutations of size Y of a set of size X. That is if I had (1,2,3) and want all permutations of size 2, 3P2, it would be (1,2) (1,3) (2,1) (2,3) (3,1) (3,2).

无论是GSL和C ++ STL只提供XPX,我可以看到。可能有人点我在C / C ++库,能做到这一点,或勾勒出一个快速,高效的存储算法?

Both the GSL and C++ STL only provide xPx that I can see. Could someone point me at a C/C++ library which can do this or spell out a fast and memory efficient algorithm?

我试图解决一个很短的密文。我已经想通了两封信,并已决定做一个强力攻击。我有ouglg ouyakl和我检查对一个非常好的字典每种排列。我已经消除了2个英文字母所以其24P7或1744364160可能性,这是没有那么糟糕。我现在已经在运行一个Perl程序,所以这将是编程时间+运行时间,总有效率的一个有趣的测试。 :)

I'm trying to solve a very short cryptogram. I've figured out two letters and have decided to do an brute force attack. I have "ouglg ouyakl" and am checking every permutation against a very good dictionary. I've eliminated 2 letters so its 24P7 or 1,744,364,160 possibilities which isn't so bad. I have a Perl program running now, so this will be an interesting test of the total efficiency of programming time + run time. :)

(不,我不只是要答案的密文。)

(No, I do not just want the answer to the cryptogram.)

推荐答案

我用的在此之前库(注意:这是C ++)在code,需要做同样的事情。它有排列组合,有和没有重复。对于您的问题,这应该足够了(未经测试...):

I've used this library before (note it is C++) in code that needed to do something similar. It has permutations and combinations, with and without repetition. For your problem, this should suffice (untested...):

std::vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);

std::vector<int>::iterator first = v.begin(), middle = v.begin() + 2, last = v.end();

do {
    // do stuff with elements in range first...middle (but dont change them)
} while(next_partial_permutation(first, middle, last));

这篇关于我如何获得XPY的所有排列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆