随笔分类 -  算法设计与分析--李春葆--上机实验题

摘要://求解装载问题 #include<stdio.h> #define MAXN 20 int n,W; int maxw; int x[MAXN]; int minm = 32767; void disp(int n){ //当x[i]等于1时,说明选择该集装箱,输出 int i; printf(" 阅读全文
posted @ 2020-01-05 20:00 Hqx_curiosity 阅读(358) 评论(0) 推荐(0)
摘要:用数组b[0...n-1]记录a[i](0<=i<=n-1)为结尾元素的最长递增子序列的长度; 序列a[]中的最长自增子序列的长度为 max(b[i])。 //求最长单调递增子序列 #include<stdio.h> #define MAXN 20 void disp(int a[],int b[] 阅读全文
posted @ 2020-01-05 17:55 Hqx_curiosity 阅读(279) 评论(0) 推荐(0)
摘要://上机实验5 -- 求解删数问题 //贪心算法 #include<stdio.h> #define MAXN 20 void delek(int a[],int k){ } void longTostr(double d,char a[]){ int i,n = 0 ; char temp; wh 阅读全文
posted @ 2019-12-11 12:36 Hqx_curiosity 阅读(272) 评论(0) 推荐(0)
摘要://上机实验题4 -- 求序列的最大元素和次大元素 #include<stdio.h> void SecondElement(int a[],int low,int high,int &max,int &sec){ // int mid; int x1,x2,x3,x4; if(high - low 阅读全文
posted @ 2019-12-11 12:35 Hqx_curiosity 阅读(446) 评论(0) 推荐(0)
摘要://上机实验题3 -- 钱币兑换问题 #include<stdio.h> void fun(int n){ int x,y,z; int count = 0; for(z=0;z<=n/5;z++){ //5分钱币的的个数 0 ——n/5 for(y=0;y<=(n-5*z)/2;y++){ //2 阅读全文
posted @ 2019-12-11 12:34 Hqx_curiosity 阅读(374) 评论(0) 推荐(0)
摘要:题目: //上机实验题1--统计求最大最小元素的平均比较次数 /*随机产生10个1~20的随机整数,设计一个算法找其中最大元素和最小元素,并统计元素之间的比较次数*/ #include<stdio.h> #include<stdlib.h> #include<time.h> #define MAXN 阅读全文
posted @ 2019-12-11 12:29 Hqx_curiosity 阅读(2468) 评论(0) 推荐(0)