假定公司出售一段長度為i英寸的鋼條的利潤為Pi,那么現(xiàn)有一根N英寸的鋼條該如何切割才能利潤大,大為多少。
在莒縣等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都做網(wǎng)站、網(wǎng)站制作 網(wǎng)站設(shè)計(jì)制作按需求定制制作,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站建設(shè),成都全網(wǎng)營銷,外貿(mào)網(wǎng)站制作,莒縣網(wǎng)站建設(shè)費(fèi)用合理。#include#includeusing namespace std;
void mycut_roin(const int p[], int length, int n, int optim_income[], int optim_solution[]);
void show_array(int arr[], int n);
int main()
{const int length = 10;
int p[length+1] = {0,1,5,8,9,10,17,17,20,24,30 };
int n;
cin >>n;
int* optim_income(new int[n + 1]);
int* optim_solution(new int[n + 1]);
mycut_roin(p, length, n, optim_income, optim_solution);
cout<< "The optimal income: "<< optim_income[n]<< endl;
while (n >0)
{cout<< optim_solution[n]<< ' ';
n -= optim_solution[n];
}
delete[] optim_income;
delete[] optim_solution;
return 0;
}
void mycut_roin(const int p[], int length, int n, int optim_income[], int optim_solution[])
{optim_income[0] = optim_solution[0] = 0;
for (int i = 1; i<= n; i++)
{int max_income = INT_MIN;
for (int j = 1; j<= i; j++)
{ int pval = (j >= length) ? p[length] : p[j];
if (pval + optim_income[i - j] >max_income)
{ max_income = pval + optim_income[i - j];
optim_solution[i] = j;
}
}
optim_income[i] = max_income;
}
show_array(optim_income, n + 1);
show_array(optim_solution, n + 1);
}
void show_array(int arr[], int n)
{for (int i = 0; i< n; i++)
{cout.width(4);
cout<< arr[i]<< ' ';
}
cout<< endl;
}
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購,新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧