演算法實驗課

2021-08-19 11:27:13 字數 1791 閱讀 9191

ps:開玩笑的,請隨意

1.格雷碼構造問題 (分治法)

//分治法

/*the sample input:

4the sample output:

1111

0111

0011

1011

1001

0001

0101

1101

1100

0100

0000

1000

1010

0010

0110

1110

*/#include using namespace std;

const int maxn=3000+5;

char s[maxn][maxn];

void gray(int row,int n)

printf("%d\n",res);

}return 0;

}

4.排兵布陣問題

//dfs遞迴列舉+剪枝

/*the sample input:

560 40 80 50 60

90 60 80 70 20

30 50 40 50 80

90 40 30 70 90

60 80 90 60 50

the sample output:

(0,2)

(1,0)

(2,4)

(3,3)

(4,1)

400*/

#include using namespace std;

const int maxn=50+5;

int maze[maxn][maxn],c[maxn],n,sum,m[maxn],solve[maxn];

bool done[maxn];

void dfs(int cur,int k) //填入位置

return;

}//剪枝:如果當前產生的攻擊力+剩餘士兵能夠產生的最大攻擊力<=sum時,剪枝

int k1=k;

for(int i=cur;i5.運動員最佳匹配問題

//匹配問題 遞迴列舉

/*the sample input:

560 40 80 50 60

90 60 80 70 20

30 50 40 50 80

90 40 30 70 90

60 80 90 60 50

23 20 14 52 16

25 14 48 98 74

1 5 45 98 47

10 25 56 97 41

20 25 18 75 94

the sample output:

the (man,woman):

(0,0)

(1,3)

(2,2)

(3,4)

(4,1)

17600

*/#includeusing namespace std;

const int maxn=100+5;

int p[maxn][maxn],q[maxn][maxn],n,c[maxn],solve[maxn],sum;

bool done[maxn];

void dfs(int cur,int k)

return;

} for(int i=0;i}int main()

return 0;

}

C 實驗課任務 多型 容器 演算法

如下 具體細節處的分析見 中 裡的部分 pragma once include include include 請填寫 呼叫stl中vector容器所需要的標頭檔案 include 請填寫 呼叫stl中sort演算法所需要的標頭檔案 using namespace std 這是我們的基類,是個抽象類...

生物實驗課趣事

上週六下午,我們生物實驗的內容為 植物的多樣性與結構 老師帶領我們從山東大學校園裡轉了乙個大圈,途中帶領我們觀察了各種各樣的植物並進行了講解。學生們總共有兩種記錄方式。其中一類拿個本子來記,老師說了什麼植物的名稱啊 科目屬啊之類的,他們都十分認真的記在本子上。另一類像我一樣,拿個相機或用手機上的照相...

課設實驗一

直接上圖 步驟 1 依照拓撲圖進行分工,需要6臺pc 2 幸運的分到了sw1 3 配置命令如下 int g0 0 description to sw3 g0 0 no switchport ip add 13.1.1.1 24 vlan 10,20 int g0 1 0 2 switchport m...