返回   cpper编程论坛 > 算法
注册账号 论坛帮助 会员列表 日历事件 搜索 今日新帖 标记版面已读

回复
 
LinkBack 主题工具 显示模式
  #1 (permalink)  
旧 2006-06-28
cat cat 当前离线
高级会员
 
注册日期: 2003-11-06
帖子: 1,550
文章: 6
cat 正向着好的方向发展
默认 问个傻问题,24点出牌总共有几种组合?

是不是
for (i = 0; i < 13; ++i)
for (j = i; j < 13; ++j)
for (k = j; k < 13; ++k)
for (l = k; l < 13; ++l)
++count;
的数目?
不过想直接计算就不会了……
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #2 (permalink)  
旧 2006-06-28
polyrandom 的头像
超级版主
 
注册日期: 2002-09-03
帖子: 3,117
文章: 20
polyrandom 正向着好的方向发展
默认

1234和4321应该不算一种组合吧?
13^4应该是不对的。
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #3 (permalink)  
旧 2006-06-28
zweily 的头像
版主
 
注册日期: 2002-09-24
帖子: 425
文章: 10
zweily 正向着好的方向发展
默认

1234和4321是一样的阿。这个就是组合阿,不是排列阿。
所以么,就是52张牌取4张牌的排列嘛
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #4 (permalink)  
旧 2006-06-29
cat cat 当前离线
高级会员
 
注册日期: 2003-11-06
帖子: 1,550
文章: 6
cat 正向着好的方向发展
默认

52张取4张的组合也不对
黑桃A 黑桃2 黑桃3 黑桃4

草花A 草花2 草花3 草花4
是同一种组合

to pora:
1234和4321认为是一样的吧。你算24点的时候可以任意组合的。
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #5 (permalink)  
旧 2006-06-29
polyrandom 的头像
超级版主
 
注册日期: 2002-09-03
帖子: 3,117
文章: 20
polyrandom 正向着好的方向发展
默认

sorry,我笔误了。我本来想说的就是,因为1234和4321是相同的,所以这样的4重循环肯定是不对的
排列组合问题
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #6 (permalink)  
旧 2006-06-29
普通会员
 
注册日期: 2006-03-08
帖子: 31
Juvexp 正向着好的方向发展
默认

C(x,y)代表从x张中选y张的组合

C(13,4) // 4张都不一样的
+C(13,3) // 仅有两张牌一样的
+C(13,2) // 仅有三张牌一样的
+C(13,1) // 4张都一样的

是不是这个
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #7 (permalink)  
旧 2006-06-29
高级会员
 
注册日期: 2006-02-11
帖子: 139
zero 正向着好的方向发展
默认

I think the answer of Juvexp is correct.
To cat: I have written a program to verify the answer. The algorithm is the most naive one. I think it is correct.

I think C(52, 4) is also correct, if we regard 4C and 4H is different. But I think since we get the same result from 4 no matter it is 4C or 4H, maybe neglecting the difference is better
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #8 (permalink)  
旧 2006-06-29
cat cat 当前离线
高级会员
 
注册日期: 2003-11-06
帖子: 1,550
文章: 6
cat 正向着好的方向发展
默认

引用:
作者: polyrandom
sorry,我笔误了。我本来想说的就是,因为1234和4321是相同的,所以这样的4重循环肯定是不对的
排列组合问题
注意内层循环的起始不是0.

to zero:
I don't think so.
For example, 2 2 3 3 is a legal combination, which is not counted in his formula. However this is a big hint, made me to remember something of the permutations and combinations

PS, would you kindly paste your code here?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #9 (permalink)  
旧 2006-06-29
高级会员
 
注册日期: 2006-02-11
帖子: 139
zero 正向着好的方向发展
默认

...
我没希望了。
Juvexp的那个方法,把(2, 3, 3, 3)和(2, 2, 3, 3)看作一种了。
这样看来,我那个code也是错的了,
我把四个数的比较用Contains了。

以前看的Combinatorics全忘光了。
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #10 (permalink)  
旧 2006-06-29
高级会员
 
注册日期: 2002-09-19
帖子: 839
文章: 7
tomato 正向着好的方向发展
默认

P(13, 4) / P(4, 4) --- 1 1 1 1
+ P(13, 1) * P(12, 2) / P(2, 2) --- 2 1 1
+ P(13, 1) * P(12, 1) --- 3 1
+ P(13 2) / P(2 2) --- 2 2

对于这种可重复的组合问题
有没有除穷举外的方法?
比如有n种物品,每种有a_i个( 1 <= i <= n )
取m个物品有几种取法
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #11 (permalink)  
旧 2006-06-30
polyrandom 的头像
超级版主
 
注册日期: 2002-09-03
帖子: 3,117
文章: 20
polyrandom 正向着好的方向发展
默认

引用:
作者: cat
注意内层循环的起始不是0.

to zero:
I don't think so.
For example, 2 2 3 3 is a legal combination, which is not counted in his formula. However this is a big hint, made me to remember something of the permutations and combinations

PS, would you kindly paste your code here?
我再脸红一下
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #12 (permalink)  
旧 2006-06-30
polyrandom 的头像
超级版主
 
注册日期: 2002-09-03
帖子: 3,117
文章: 20
polyrandom 正向着好的方向发展
默认

正确算法应该是:
C(13, 4 ) = 715
C(13, 3 ) * 3 = 858
C(13, 2 ) * 3 = 234
C(13, 1 ) = 13

验证程序:
代码:
#include <iostream> #include <set> #include <vector> #include <algorithm> using namespace std; int main() { set<vector<int> > cardSets; for( int i = 0; i < 13; ++i ) for( int j = 0; j < 13; ++j ) for( int k = 0; k < 13; ++k ) for( int l = 0; l < 13; ++l ) { int cards[] = { i, j, k, l }; std::sort( cards, cards + sizeof( cards ) / sizeof( *cards ) ); cardSets.insert( vector<int>( cards, cards + sizeof( cards ) / sizeof( *cards ) ) ); } cout << cardSets.size() << endl; }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #13 (permalink)  
旧 2006-06-30
普通会员
 
注册日期: 2006-03-08
帖子: 31
Juvexp 正向着好的方向发展
默认

引用:
作者: tomato
P(13, 4) / P(4, 4) --- 1 1 1 1
+ P(13, 1) * P(12, 2) / P(2, 2) --- 2 1 1
+ P(13, 1) * P(12, 1) --- 3 1
+ P(13 2) / P(2 2) --- 2 2

对于这种可重复的组合问题
有没有除穷举外的方法?
比如有n种物品,每种有a_i个( 1 <= i <= n )
取m个物品有几种取法
还应该加上4张都一样的:P(13,1)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #14 (permalink)  
旧 2006-06-30
高级会员
 
注册日期: 2002-09-19
帖子: 839
文章: 7
tomato 正向着好的方向发展
默认

引用:
作者: Juvexp
还应该加上4张都一样的:P(13,1)
//shame...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #15 (permalink)  
旧 2006-06-30
cat cat 当前离线
高级会员
 
注册日期: 2003-11-06
帖子: 1,550
文章: 6
cat 正向着好的方向发展
默认

好像都是hardcode的算法嘛,5张牌就不灵了
不过总比没有好……
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #16 (permalink)  
旧 2006-06-30
polyrandom 的头像
超级版主
 
注册日期: 2002-09-03
帖子: 3,117
文章: 20
polyrandom 正向着好的方向发展
默认

引用:
作者: cat
好像都是hardcode的算法嘛,5张牌就不灵了
不过总比没有好……
你不要污蔑呀,我的程序可以easily扩展到5张的,就是算法复杂度有点那个
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #17 (permalink)  
旧 2006-06-30
cat cat 当前离线
高级会员
 
注册日期: 2003-11-06
帖子: 1,550
文章: 6
cat 正向着好的方向发展
默认

引用:
C(13, 4 ) = 715
C(13, 3 ) * 3 = 858
C(13, 2 ) * 3 = 234
C(13, 1 ) = 13
Oh, 没仔细看,不过还是不知道怎么扩展
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #18 (permalink)  
旧 2006-07-03
polyrandom 的头像
超级版主
 
注册日期: 2002-09-03
帖子: 3,117
文章: 20
polyrandom 正向着好的方向发展
默认

S(n) = Sum(i = 1 to n)( C( 13, i ) * C( n - 1, i - 1 ) )
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #19 (permalink)  
旧 2006-07-04
高级会员
 
注册日期: 2004-12-06
帖子: 142
哑巴英语 正向着好的方向发展
默认

引用:
作者: polyrandom
S(n) = Sum(i = 1 to n)( C( 13, i ) * C( n - 1, i - 1 ) )

怕不很对
能出5张一样的么
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #20 (permalink)  
旧 2006-07-04
polyrandom 的头像
超级版主
 
注册日期: 2002-09-03
帖子: 3,117
文章: 20
polyrandom 正向着好的方向发展
默认

引用:
作者: 哑巴英语

怕不很对
能出5张一样的么
啊呀,那就不是一样的问题了。
扑克牌的花色这么少,真是不爽
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
回复

书签

主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码
Trackbacks are 启用
Pingbacks are 启用
Refbacks are 启用



所有时间均为格林尼治时间 +9。现在的时间是 02:02 PM


Powered by vBulletin® 版本 3.7.0
版权所有 ©2000 - 2008,Jelsoft Enterprises Ltd.
(C) Copy Right All Right Reserved 2001 - 2007

Search Engine Friendly URLs by vBSEO 3.1.0