- 博客(12)
- 收藏
- 关注
原创 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
原创 图的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
481
原创 回溯法解决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
696
原创 二分查找递归非递归实现(分治法)
#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
350
原创 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
原创 独立最优任务调度(动态规划)
#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
375
原创 棋盘覆盖问题(分治法)
#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
原创 构造哈夫曼编码(贪心思想)
#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
原创 单链表尾插法(顺序插入)
尾插法实质上是始终使新构造的结点插入到上一个构造的结点和NULL之间而头插法是使其始终插入在头节点和上一个构造的结点之间
2020-11-15 20:50:47
530
原创 单链表的头插法(倒叙插入)基于先构造头节点
#include<bits/stdc++.h>using namespace std;//链表typedef struct LNode{ int data; struct LNode* next;}* LinkList;void CreateList_L(LinkList& L){ int input; L =(struct LNode*)malloc(sizeof(LNode)); L->next = NULL; Li
2020-11-15 20:45:46
260
原创 单链表倒叙插入(基于先构造尾部的思路)
#include<bits/stdc++.h>using namespace std;//链表typedef struct LNode{ int data; struct LNode* next;}* LinkList;void CreateList_L(LinkList& L, int n){ int sumn = n; LinkList p = NULL; while(n--) { LinkList te
2020-11-15 17:48:01
136
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人