摘要:
/*最小重量机器问题*/ #include 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]; //x[i]临时存放第i个... 阅读全文
摘要:
/*旅行售货员问题回溯法*/ #include #define N 4 int cc,//当前路径费用 bestc;//当前最优解费用 int a[N+1][N+1];//邻接矩阵,存放图的信息 int bestx[N+1];//当前最优解 int x[N+1];//当前解 void inputAjac() { int i,j; printf("... 阅读全文
摘要:
#include 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]]!=INF&&g[x[t]][1]!=... 阅读全文
摘要:
/*非递归二分查找*/ #include 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=(low+high)/2; if(a[... 阅读全文
摘要:
/*递归二分查找*/ #include 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("%d",&key); int ... 阅读全文
摘要:
#include 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"); scanf("%d",&n); ... 阅读全文