算法
DC空白
这个作者很懒,什么都没留下…
展开
-
回溯法求解0-1背包问题
下面展示一些 内联代码片。#include <bits/stdc++.h>#include <stdio.h>using namespace std;#define maxn 10000/*测试用例8 10030 40 20 5 15 60 25 1047 30 9 8 15 66 12 11*//*5 102 2 6 5 46 3 5 4 6*/typedef struct{ int w;//物品重量 int v;//物品价值原创 2020-12-15 22:04:43 · 210 阅读 · 0 评论 -
汽车加油问题
#include<bits/stdc++.h>#include<stdio.h>using namespace std;int a[10000];//储存相邻加油站的间距int min_times(int k,int n){ int t=0;//加油次数 int sum=a[0];//已行驶的距离 for(int i=1; i<k+1; i++) { sum+=a[i]; if(sum>n)//若原创 2020-12-16 16:23:41 · 98 阅读 · 0 评论 -
图的m着色问题
#include <bits/stdc++.h>#include <stdio.h>using namespace std;#define maxn 10000int road[maxn][maxn];//路径的邻接矩阵int x[maxn];//解向量int n;//顶点数int m;//可选颜色个数int sum;//解的个数bool is_color(int t)//判断染色是否可行{ for(int j=1; j<=n; j++)原创 2020-12-17 16:57:07 · 95 阅读 · 0 评论 -
旅行售货员问题(回溯法求解)
#include <stdio.h>#include <bits/stdc++.h>using namespace std;#define maxn 1000#define NoEdge 0x3f3f3fint m;//路径数int n;//顶点数int road[maxn][maxn]= {NoEdge}; //路径的邻接矩阵int x[maxn];//当前解int bestx[maxn];//最优解int l;//当前路径长度int bestl=NoEdg原创 2020-12-17 21:17:51 · 1683 阅读 · 0 评论 -
最小重量机器设计问题(回溯法)
#include <bits/stdc++.h>#include <stdio.h>using namespace std;#define maxn 1000int n;//部件个数int m;//供货商个数int max_c;//最大价格int w[maxn][maxn];//价格int c[maxn][maxn];//费用int cc;//当前价格int cw;//当前重量int bestw=0x3f3f3f;//最小重量int bestx[maxn]原创 2020-12-22 22:24:19 · 926 阅读 · 0 评论 -
工作分配问题
#include <bits/stdc++.h>using namespace std;#define maxn 1000int n;int cc;//当前费用int bestc=0x3f3f3f;//最少费用int c[maxn][maxn];//第件工作第j个人需要的费用int x[maxn];//解空间void BackTrack(int i){ if(i==n) { if(cc+c[i][x[i]]<bestc) {原创 2020-12-23 17:09:44 · 155 阅读 · 0 评论