由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Small question about algorithm
相关主题
generate unique integer ID from columns in SQL table (转载Algorithms and Data Structures那本比较好呢?
scala大牛幫看看這個map是為什麽?不太明白[c++] virtual member?
shortest path algorithm(dijkstra)的变形Introduction to Algorithms | The MIT Press
MatLab Code真心求助 .net c# 算法,数据结构书,网站
C -> assemblyquestion about google algorithm/architecture (转载)
[转载] What search method is used in exists()?请教express create session的问题
请问有什么c++ algorithm and data structure 好的书吗?问个树遍历的线程化问题
sort algorithma simple question about constructor
相关话题的讨论汇总
话题: int话题: std话题: small
进入Programming版参与讨论
1 (共1页)
l********s
发帖数: 358
1
I want generate the combination of several components. For example, I have 4
components which are labeled by 1, 2, 3, 4. So the unique different
combination will be 1, 2, 3, 4, 12, 13, 14, 23, 24, 34, 123, 124, 134, 234,
1234. My idea is that I could create a set of combination, as: std::set< std
already exist in the set, since 123 is the same with 213, 231, and 321, and I just
need one combination.
Is there any better idea? Thanks a lot
k****f
发帖数: 3794
2
你的效率太低了
http://www.merriampark.com/comb.htm

4
,
std
and I just

【在 l********s 的大作中提到】
: I want generate the combination of several components. For example, I have 4
: components which are labeled by 1, 2, 3, 4. So the unique different
: combination will be 1, 2, 3, 4, 12, 13, 14, 23, 24, 34, 123, 124, 134, 234,
: 1234. My idea is that I could create a set of combination, as: std::set< std
: already exist in the set, since 123 is the same with 213, 231, and 321, and I just
: need one combination.
: Is there any better idea? Thanks a lot

l********s
发帖数: 358
3
Thanks for the information, however I don't understand the algorithm in the
class. In the class "CombinationGenerator(int n, int r)", it requires r < n,
and in my case, I need r = n.
l********s
发帖数: 358
4
Hi, I used your keywords "combination generate" to google and find useful
information for my case.
http://www.programmersheaven.com/mb/beginnercpp/283845/283845/readmessage.aspx
Thanks for help again.
t****t
发帖数: 6806
5
你就不能多花点时间读读, 多花点时间想想么.
第一, 那个link里的程序是列出所有的C(n, r)组合, 不是\union_{r=1}^n C(n, r),
你需要自己循环r;
第二, 算法就是getNext()那一段, 除了这一段, 其它的部分都很蠢
第三, 你哪只眼睛看到说要求r 第四, 就算要求 r
the
n,

【在 l********s 的大作中提到】
: Thanks for the information, however I don't understand the algorithm in the
: class. In the class "CombinationGenerator(int n, int r)", it requires r < n,
: and in my case, I need r = n.

l********s
发帖数: 358
6
Hey,
public CombinationGenerator (int n, int r) {
if (r > n) {
throw new IllegalArgumentException ();
}
I don't want to argue with you. But I really see r > n => throw exception.
Anyway, thanks for everyone's response and support.
t****t
发帖数: 6806
7
r>n的逆条件是啥?
r 多用脑,少用嘴

【在 l********s 的大作中提到】
: Hey,
: public CombinationGenerator (int n, int r) {
: if (r > n) {
: throw new IllegalArgumentException ();
: }
: I don't want to argue with you. But I really see r > n => throw exception.
: Anyway, thanks for everyone's response and support.

c**l
发帖数: 12
8
这个本质上就是,keep index sorted.
8queen solution
For OP's question, create a n-element array of CombinationGenerator, let r
to be from 1 to n.
Good stuff.

你的效率太低了
http://www.merriampark.com/comb.htm
4
,
std
and I just

【在 k****f 的大作中提到】
: 你的效率太低了
: http://www.merriampark.com/comb.htm
:
: 4
: ,
: std
: and I just

s****u
发帖数: 118
9
int n = 4;
int elems[] = { 1, 2, 3, 4 };
for (int i = 0; i < (1 << n); ++i) {
for (int k = 0; k < n; ++k) if (i & (1 << k)) {
// outputs elems[k]...
}
}

4
,
std
it
and I just

【在 l********s 的大作中提到】
: I want generate the combination of several components. For example, I have 4
: components which are labeled by 1, 2, 3, 4. So the unique different
: combination will be 1, 2, 3, 4, 12, 13, 14, 23, 24, 34, 123, 124, 134, 234,
: 1234. My idea is that I could create a set of combination, as: std::set< std
: already exist in the set, since 123 is the same with 213, 231, and 321, and I just
: need one combination.
: Is there any better idea? Thanks a lot

1 (共1页)
进入Programming版参与讨论
相关主题
a simple question about constructorC -> assembly
讨论个idea题[转载] What search method is used in exists()?
请教C++请问有什么c++ algorithm and data structure 好的书吗?
请问个老的COMBINATION题sort algorithm
generate unique integer ID from columns in SQL table (转载Algorithms and Data Structures那本比较好呢?
scala大牛幫看看這個map是為什麽?不太明白[c++] virtual member?
shortest path algorithm(dijkstra)的变形Introduction to Algorithms | The MIT Press
MatLab Code真心求助 .net c# 算法,数据结构书,网站
相关话题的讨论汇总
话题: int话题: std话题: small