背包算法

背包算法


//ArrayList needs=new ArrayList();
//            #region 加载测试数据
//            for (int i = 0; i < 5; i++)
//            {
//                needs.Add(3);
//            }
//            for (int i = 0; i < 7; i++)
//            {
//                needs.Add(1.55);
//            }
//            for (int i = 0; i < 9; i++)
//            {
//                needs.Add(1.66);
//            }
 
//            #endregion

//            //从大到小排序
//            IComparer myComperMethod = new comper();
//            needs.Sort(myComperMethod);

//            string result = string.Empty;
//            //迭代方法
//            for (int i = 0; i < needs.Count; )
//            {
//                double temp =double.Parse(needs[i].ToString());
//                ArrayList tempResult = new ArrayList();
//                tempResult.Add(needs[i]);
//                needs.RemoveAt(i);

//                for (int j = 0; j < needs.Count; )
//                {
//                    if (temp + double.Parse(needs[j].ToString()) > 6)
//                    {
//                        j++;
//                    }
//                    else
//                    {
//                        temp += double.Parse(needs[j].ToString());
//                        tempResult.Add(needs[j]);

//                        needs.RemoveAt(j);
//                    }
//                }

//                //记录结果
//                for (int k= 0; k < tempResult.Count; k++)
//                {
//                    result += tempResult[k].ToString() + ",";
//                }
//                result += "<br>";
//            }
           
//            Response.Clear();
//            Response.Write(result);
//            Response.End();

你可能感兴趣的:(背包算法)