算法
DC空白
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
回溯法求解0-1背包问题
下面展示一些 内联代码片。 #include <bits/stdc++.h> #include <stdio.h> using namespace std; #define maxn 10000 /*测试用例 8 100 30 40 20 5 15 60 25 10 47 30 9 8 15 66 12 11 */ /* 5 10 2 2 6 5 4 6 3 5 4 6 */ typedef struct { int w;//物品重量 int v;//物品价值原创 2020-12-15 22:04:43 · 303 阅读 · 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 · 165 阅读 · 0 评论 -
图的m着色问题
#include <bits/stdc++.h> #include <stdio.h> using namespace std; #define maxn 10000 int 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 · 152 阅读 · 0 评论 -
旅行售货员问题(回溯法求解)
#include <stdio.h> #include <bits/stdc++.h> using namespace std; #define maxn 1000 #define NoEdge 0x3f3f3f int 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 · 1836 阅读 · 0 评论 -
最小重量机器设计问题(回溯法)
#include <bits/stdc++.h> #include <stdio.h> using namespace std; #define maxn 1000 int 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 · 1002 阅读 · 0 评论 -
工作分配问题
#include <bits/stdc++.h> using namespace std; #define maxn 1000 int 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 · 296 阅读 · 0 评论
分享