分类: 〖科大〗 |
据大家反映很變態的Assignment
3昨天晚上終于可以有時閒編了。
連續奮戰,終于在今早7點整突擊完了。寫了270行,而最後一問並沒有大家說得那麽複雜。不過好像Daniel LOU沒有講深度優先搜索和全排列的生成算法,所以大家都不知所措,居然有人還用rand隨機生成結果,佩服!
根據DFS,最後一個list_permutation我只用了一個self-defined function,20行搞定,而list_permutation除了算一個length外沒有別的語句,直接調用self-defined function,即permutation。
我把我的這個void function貼上來,為大家在deadline前提供思路,紅色的參數是關鍵,不能全告訴大家了,自己想吧。
void permutation(const char s[], char p[], int l, int k, int j) // l is length, k is current length of p, j is the pos of s
{
int find (
const char s[ ], char ch);
if
(j<l)
{
if (k==l)
{p[l]='\0'; cout<<p<<endl;}
else
{
if
(find(p,s[j])==-1)
{
p[k]=s[j];
permutation(****** *);
p[k]='\0';
permutation(******* );
}
else
permutation(******* );
}
}
}
連續奮戰,終于在今早7點整突擊完了。寫了270行,而最後一問並沒有大家說得那麽複雜。不過好像Daniel LOU沒有講深度優先搜索和全排列的生成算法,所以大家都不知所措,居然有人還用rand隨機生成結果,佩服!
根據DFS,最後一個list_permutation我只用了一個self-defined function,20行搞定,而list_permutation除了算一個length外沒有別的語句,直接調用self-defined function,即permutation。
我把我的這個void function貼上來,為大家在deadline前提供思路,紅色的參數是關鍵,不能全告訴大家了,自己想吧。
void permutation(const char s[], char p[], int l, int k, int j) // l is length, k is current length of p, j is the pos of s
{
}
后一篇:近日……