![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
计算机算法分析与设计
zili_m
这个作者很懒,什么都没留下…
展开
-
01背包问题 -- 动态规划
/*0-1背包问题*/#include<stdio.h> int V[200][200]; //前i个物品装入容量为j的背包中获得的最大价值 int max(int a,int b) { if(a>=b) return a; else return b; } int KnapSack(int n,int w[],...原创 2018-11-04 21:18:32 · 271 阅读 · 0 评论 -
图的m着色问题
#include<stdio.h>int color[100],sum; bool ok(int k,int c[100][100]){ for(int i=1;i<k;i++) if((c[k][i]==1)&&(color[i]==color[k])) return false; ...原创 2018-11-05 09:10:57 · 803 阅读 · 0 评论 -
汽车加油问题
#include<stdio.h>int greedy(int x[],int n,int k){ int sum=0; for(int j=0;j<=k;j++){ if(x[j]>n) { printf("No Solution!\n"); return -1; } } for (int i=0,s=0;i&l...原创 2018-11-05 09:10:54 · 1561 阅读 · 0 评论 -
旅行售货商问题 -- 回溯法
/*旅行售货员问题回溯法*/#include<stdio.h> #define N 4 int cc,//当前路径费用 bestc;//当前最优解费用 int a[N+1][N+1];//邻接矩阵,存放图的信息 int bestx[N+1];//当前最优解 int x[N+1];//当前解 void inputAjac() { int i,...原创 2018-11-05 09:10:42 · 2534 阅读 · 2 评论 -
旅行售货商问题 1
#include<iostream> using namespace std; const int INF = 10000000; int n, cc = 0, bestc = INF; int **g; int *x, *bestx; void travel(int t) { if(t==n){ if(g[x[t-1]][x[t]]!=I...原创 2018-11-05 09:10:32 · 585 阅读 · 0 评论 -
二分搜索的非递归实现
/*非递归二分查找*/#include<stdio.h>void main(){ int a[10]={11,21,31,41,51,61,71,81,91,101}; int low=0,high=9; int key; printf("请输入要查找的数:"); scanf("%d",&key); while(low<=high){ int mid...原创 2018-11-04 21:47:25 · 172 阅读 · 0 评论 -
二分搜索的递归实现
/*递归二分查找*/#include<stdio.h>int select(int a[],int low,int high,int key);void main(){ int a[10]={11,21,31,41,51,61,71,81,91,101}; int low=0,high=9; int key; printf("请输入要查找的数:"); scanf("%...原创 2018-11-04 21:45:19 · 898 阅读 · 0 评论 -
独立任务最优调度问题
#include <stdio.h> int main() { int n; int *a, *b,*t; int i,k; int sa=0; int result=1000000; printf("please input the number of tasks:\n"); s...原创 2018-11-04 21:42:29 · 260 阅读 · 0 评论 -
Huffman Tree -- Huffman编码
#include <stdlib.h> #include <stdio.h> #include <string.h>typedef struct HuffmanTree { int weight; int parent, lchild, rchild; }HuffmanTree; typedef struct CodeNode...原创 2018-11-04 21:39:23 · 200 阅读 · 0 评论 -
01背包问题 -- 回溯法 2
/*0-1背包伪代码*/#include <iostream> using namespace std; template<class Typew,class Typep> class Knap //Knap类记录解空间树的结点信息 { template<class Typew,class Typep>...原创 2018-11-04 21:26:13 · 478 阅读 · 0 评论 -
01背包问题 -- 回溯法 1
/*0-1背包回溯法实现*/#include <stdio.h>#include <conio.h>int n; //物品数量double c; //背包容量double v[100]; //各个物品的价值double w[100]; //各个物品的重量double cw = 0.0; //当前背包重量double cp = 0.0; /...原创 2018-11-04 21:23:34 · 1565 阅读 · 0 评论 -
最小重量机器问题
/*最小重量机器问题*/#include<stdio.h> int w[100][100]; //w[i][j]为第i个零件在第j个供应商的重量 int c[100][100]; //c[i][j]为第i个零件在第j个供应商的价格 int bestx[100]; //bestx[i]表示一次搜索到底后的最优解,用来存放第i个零件的供应商, int x[100]; ...原创 2018-11-05 09:11:00 · 306 阅读 · 0 评论