全排列問題
#include
const
int maxn =11;
int n,p[maxn]
,hashtable[maxn]=;
void
generatep
(int index)
printf
("\n");
return;}
for(
int x =
1;x<=n;x++)}
}int
main
(void
)
推演:
hashtable = false
n =3
generatep(1
):index =1if
(index == n+
1)不滿足
for: x =1if
(hashtable[x]
== false)滿足:
p[1]
=1hashtable[1]
= true
generatep(2
):index =2if
(index == n+
1)不滿足
for: x =1if
(hashtable[x]
== false)不滿足
x =2if
(hashtable[x]
== false)滿足:
p[2]
=2hashtable[2]
= true
generatep(3
):index =3if
(index == n+
1)不滿足
for: x =1if
(hashtable[x]
== false)不滿足
x =2if
(hashtable[x]
== false)不滿足
x =3if
(hashtable[x]
== false)滿足:
p[3]
=3hashtable[3]
= true
generatep(4
):if(index == n+
1)滿足:
輸出:123
hashtable[3]
= false
hashtable[2]
= false
x =3if
(hashtable[x]
== false)滿足:
p[2]
=3hashtable[3]
= true
generatep(3
):index =3if
(index == n+
1)不滿足
for: x =1if
(hashtable[x]
== false)不滿足
x =2if
(hashtable[x]
== false)滿足:
p[3]
=2hashtable[2]
= true
generatep(4
):if(index == n+
1)滿足:
輸出:132
hashtable[2]
= false
x =3if
(hashtable[x]
== false)不滿足
hashtable[3]
= false
hashtable[1]
= false
x =2.
....
.
八皇后問題:
#include
#include
const
int maxn =11;
int count =0;
int n,p[maxn]
,hashtable[maxn]=;
void
generatep
(int index)
for(
int x =
1;x<=n;x++)}
if(flag)}}
}int
main
(void
)
演算法學習筆記 DAY2
滿足要求 雜湊表 平均情況 雜湊表 最糟情況 陣列 鍊錶 查詢o 1 o 1 o 1 o n o n o n o 1 o 1 o 1 o n o n o n 插入o 1 o 1 o 1 o n o n o n o n o n o n o 1 o 1 o 1 刪除o 1 o 1 o 1 o n o n...
演算法刷題 筆記(Day2)
題目描述 判斷乙個整數是否是回文數。回文數是指正序 從左向右 和倒序 從右向左 讀都是一樣的整數。解題思路 一 1.回文數的先決條件x 0.2.利用序列型別資料的性質,先轉字串再進行切片翻轉str 1 題解 class solution def ispalindrome self,x int boo...
聽課筆記Day2
命名規則 1.只能是字母 數字 下劃線 2.不能以數字開頭 3.不能是關鍵字 4.區分大小寫 5.見其名知其意 變化的量 具有特殊意義的單詞 false none true and as assert break class continue def del elif else except fin...