回溯法实现最小重量机器设计

本文探讨了如何运用回溯法来解决最小重量机器设计的问题。通过详细的步骤解析,阐述了如何构建问题的约束条件,并利用回溯策略进行有效的搜索,最终找到最优解。文章还讨论了回溯法在解决这类优化问题中的优势和适用场景。
摘要由CSDN通过智能技术生成
#include<iostream>
#define INF 65535
using namespace std;
class Shop{  //商店类
public:
    double *w;  //商店内每个物品的质量
    double *v;  //商店内每个物品的价格
};
class Tool{  //代组装机器类
public:
    Shop *shop;  //商店数组
    int m;  //商店个数
    int num;  //零件个数
    int v;  //最大价格
    int bestw;  //最小质量
    int tempw;  //当前质量
    int tempv;  //当前价格
    int *best_step;  //最优方案
    int *temp_step;  //当前方案
    int *min_each_depth;  //对于每个零件能得到的最小的质量
public:
    /* 获取机器内每个零件的最小质量便于计算上界函数 */
    int Min(int depth){
        int min = shop[1].w[depth];
        for(int i = 1;i <= m;i++)
            if(shop[i].w[depth] < min)
                min = shop[i].w[depth];
        return min;
    }
    /* 初始化 */
    void Initial(){
        cout<<"please input the number of the tools and the nomber of shops and the Maximum price: "<<endl;
        cin>>num>>m>>v;
        best_step = new int[num * 2];
        temp_step 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值