标签:
#ifndef ASSEMBLE_LINE_H
#define ASSEMBLE_LINE_H
#include<iostream>
#include<string>
class AssembleLine{
private:
int AssOneIn; //第一条装配线输入的代价
int AssTwoIn; //第二条装配线输入的代价
int AssOneOut; //第一条装配线输出的代价
int AssTwoOut; //第二条装配线输出的代价
int *Ass_one; //第一条装配线零件装配代价
int Len_one; //第一条装配线的长度
int *Ass_two; //第二条装配线零件的装配代价
int Len_two; //第二条装配线的长度
int *AssOneToTwo; //第一条装配线转入第二条的代价
int *AssTwoToOne; //第二条装配线转入第一条的代价
int *f1; //记录第一条装配线
int *f2; //记录第二条装配线
public:
AssembleLine(int *&ass1,int len1,int *&ass2,int len2):Ass_one(ass1),Ass_two(ass2),Len_one(len1),Len_two(len2){
}
int assembleMin();
};
#include"AssembleLine.h"
#define Min(a,b) a<b? a:b
int AssembleLine::assembleMin(){
f1[0]=this->AssOneIn+this->Ass_one[0];
f2[0]=this->AssTwoIn+this->Ass_two[0];
for(int i=1;i<this->Len_one; i++){
f1[i]=Min((f1[i-1]+this->Ass_one[i]),(f2[i-1]+this->Ass_one[i]+this->AssTwoToOne[i-1]));
f2[i]=Min((f2[i-1]+this->Ass_two[i]),(f2[i-1]+this->Ass_two[i]+this->AssOneToTwo[i-1]));
}
return Min((f1[this->Len_one-1]+this->AssOneOut),(f2[this->Len_two-1]+this->AssTwoOut));
}
标签:
原文地址:http://www.cnblogs.com/yml435/p/4655516.html