作者sorryChen (陳揚和)
看板Programming
標題在c++中產生n個0和m個1的排列
時間Sun Nov 8 14:07:00 2009
這應該是個簡單recursive可以完成的問題
而且我查到stl的next_permutation可用,但好像僅適用在n個不同的element
用在這個問題 就太多pattern被重複列舉了...
在Python中有個好用的關鍵字叫yield...可以在停在function的某行return
下次call此funciton時繼續
我的問題是,有沒有什麼stl或object可以在c++做同樣的事呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 204.140.141.12
1F:→ eva19452002:用recursive你的記憶體很快就爆了 118.169.100.9 11/08 23:15
2F:→ sorryChen:thanks.. my n<30 m<10, so it is ok 128.125.87.33 11/09 03:08
3F:推 Huangs:寫個recursive才幾行而已 比打上來還快 XD 218.167.2.50 11/09 05:59
4F:→ sorryChen:but I need to test for each enum pat 128.125.87.33 11/09 10:07
5F:→ sorryChen:so I need to write to a file or 128.125.87.33 11/09 10:09
6F:→ sorryChen:test in the recursive. 128.125.87.33 11/09 10:09
7F:→ sorryChen:yield is more elegant. 128.125.87.33 11/09 10:10
8F:推 yauhh:最簡單是把1~N做next_permutation,然後 59.112.230.115 11/09 11:19
9F:→ yauhh:用排列的數字當索引,查查是n或m. 59.112.230.115 11/09 11:20
10F:→ yauhh:C++不專處理pattern,在這方面當然不elegant. 59.112.230.115 11/09 11:21
11F:→ yauhh:喔,我搞錯了,我講的會重複列出排列情況 218.160.215.75 11/09 21:24
12F:→ bigpigbigpig:給原po:n 個元素不必完全不同也可以 61.61.252.34 04/19 13:35
13F:→ bigpigbigpig:使用 next_permutation() 哦! 61.61.252.34 04/19 13:36