
算法设计
yolojia
这个作者很懒,什么都没留下…
展开
-
TSP(分支限界法)
#include<bits/stdc++.h>#define INF 60000#define n 4using namespace std;int** a;int bestc = INF;int* bestx;int* minout;int sum_minout;class Node{public: int t_; int ccost_; int least_cost_; int* x_;public: void Init_Nod原创 2020-12-29 11:58:44 · 1795 阅读 · 0 评论 -
图的m涂色问题(回溯法)
#include<bits/stdc++.h>using namespace std;class Color{private: int n_;//顶点数 int m_;//颜色数 int **Martix;//邻接矩阵 int *x; //当前解 int solution_num_; //解的个数 bool OK(int k); //判断第k个涂色是否与前边的涂色冲突 void Backtrack(int原创 2020-12-24 21:31:15 · 482 阅读 · 0 评论 -
回溯法解决0-1背包问题(迭代)
#include<bits/stdc++.h>using namespace std;class Knap{ friend int Knapsack(int*,int*,int,int,Knap&);public: int c; int n; int* w; int* p; int cw; int cp; int bestp; int *x, //当前解 *bestx; //当前最优解原创 2020-12-22 15:56:48 · 1393 阅读 · 5 评论 -
回溯法解决0-1背包问题(递归)
#include<bits/stdc++.h>using namespace std;class Knap{ friend int Knapsack(int*,int*,int,int);private: int c; int n; int* w; int* p; int cw; int cp; int bestp; int Bound(int i); void Backtrack(int i);};int原创 2020-12-20 15:45:14 · 697 阅读 · 0 评论 -
二分查找递归非递归实现(分治法)
#include<bits/stdc++.h>using namespace std;/*初始化数组*/int Init_Array(int* & a){ cout<<"请输入数组大小"<<endl; int n; cin>>n; a = new int [n]; cout<<"请输入数组元素(保证输入为有序数组)"<<endl; for(int i=0;i<n;i+原创 2020-12-16 10:57:43 · 351 阅读 · 0 评论 -
0-1背包问题(动态规划)
#include<bits/stdc++.h>#define n 5#define capacity 10using namespace std;int w[n+1] = {-1,2,2,6,5,4};int v[n+1] = {-1,6,3,5,4,6};int m[n+1][capacity+1];int x[n+1];int min(int a,int b){ if(a<b) return a; return b;}int max(int a,int b)原创 2020-12-16 10:55:43 · 104 阅读 · 0 评论 -
独立最优任务调度(动态规划)
#include<bits/stdc++.h>#define n 6#define suma 31#define maxtime 10000using namespace std;int a[n+1] = {-1,2,5,7,10,5,2};int b[n+1] = {-1,3,8,4,11,3,4};int f[n+1][suma+1];int min(int a,int b){ if(a<b) return a; return b;}int max(int原创 2020-12-16 10:54:36 · 376 阅读 · 0 评论 -
棋盘覆盖问题(分治法)
#include<bits/stdc++.h>using namespace std;int board[10000][10000];int tile = 1;void ChessBoard(int tr,int tc,int dr,int dc,int size_){ if(size_ == 1) return ; int t = tile++; int s = size_ / 2; //填充左上角 if(dr < tr+s原创 2020-12-16 10:52:59 · 253 阅读 · 0 评论 -
构造哈夫曼编码(贪心思想)
#include<bits/stdc++.h>#define char_num 6using namespace std;typedef struct Tree{ string name_; int weight_; struct Tree* left, *right;}*BinTree;struct cmp{ bool operator()(const BinTree& a,const BinTree& b){ return a->原创 2020-12-16 10:51:17 · 257 阅读 · 0 评论