日期:2014-05-19  浏览次数:20768 次

方程组求解 比较有挑战性,盼高手帮忙
有一根料长   6000   mm,现在要分成以下方案

//1589   、560、2376、1600、2100           每根材料的长度
//3               10       2           3             2             根数

求怎么分这6000mm     利用率最高;
如:

//1589   、560、2376、1600、2100           每根材料的长度
//0               2       2           0             0         根数

这个分法的利用率达到98%

我是这样解的:
using   System;

namespace   ConsoleApplication1
{
///   <summary>
///   Class1   的摘要说明。
///   </summary>
class   Class1
{
///   <summary>
///   应用程序的主入口点。
///   </summary>
[STAThread]
static   void   Main(string[]   args)
{
// //1589   、560、2376、1600、2100
// //3               10       2           3             2
int   sum1   =   0;
int   i   =   0,   j   =   0,   m   =   0,   n   =   0,   x   =   0;
int   x1,   x2,   x3,   x4,   x5;


for   (m   =   0;   m   <   3;   m++)
{
for   (x   =   0;   x   <   3;   x++)
{
for   (n   =   0;   n   <   4;   n++)
{
//int   sum1=1589*i+560*j+2376*m+1600*n+2100*x;
for   (i   =   0;   i   <   4;   i++)
{
for   (j   =   0;   j   <   11;   j++)
{
sum1   =   1589*i   +   560*j   +   2376*m   +   1600*n   +   2100*x   +i*10+j*10+m*10+n*10;
if   (sum1   <=   6000)
{
x1   =   i;
x2   =   j;
x3   =   m;
x4   =   n;
x5   =   x;

Console.Write( "&&&&&&&&&&&&&&&&&&&& ");
Console.Write(string.Format( "\n "));
Console.Write(string.Format( "1589x1:{0}\n ",   i));
Console.Write(string.Format( "560x2:{0}\n ",   j));
Console.Write(string.Format( "2376x3:{0}\n ",   m));
Console.Write(string.Format( "1600x4:{0}\n ",   n));
Console.Write(string.Format( "2100x5:{0}\n ",   x));
Console.Write(string.Format( "sum1:{0}\n ",   (double)sum1));
Console.Write(string.Format( "百分比:{0}%\n ",   (double)sum1/(double)6000));
Console.Write( "========== ");
}
else
{
continue;
}
}
}
}
}
}
}
}
}

但这个并不是一个通用的解法,如我们还要分1700(3),1800(2),2500(2)   如按上面的写法就将有8个FOR   了,这根本没有通用性可言;
希望得到更位仁兄的帮助