A     B     C  三个岗位
甲  30    50    25
乙  35    30    20
丙  45    40    30甲乙丙三人,用C#编写一个程序,算出三人一天共同创造的价值最大

解决方案 »

  1.   

     DataTable _Table = new DataTable();            _Table.Columns.Add("名字");
                _Table.Columns.Add("A");
                _Table.Columns.Add("B");
                _Table.Columns.Add("C");            _Table.Rows.Add(new object[] {"甲", 30, 50, 25});
                _Table.Rows.Add(new object[] {"乙", 35, 50, 20});
                _Table.Rows.Add(new object[] {"丙", 45, 40, 30});使用TABLE解决比较好玩
                DataColumn _Column = new DataColumn("Count");
                _Column.Expression = "convert(A,'System.Int32')+convert(B,'System.Int32')+convert(C,'System.Int32')";
                _Table.Columns.Add(_Column);
                object _Object =_Table.Compute("Max(Count)","");            
                _Table.Columns.Remove(_Column);
                MessageBox.Show(_Object.ToString());
      

  2.   

    我理解是每人只能从事一个岗位
    看哪种岗位的组合 创造的价值最大 就是遍历
    这个算法应该叫回溯 没什么优化 但能实现要求
    class Program
        {
            static int[,] data = new int[3, 3] { { 30, 50, 25 }, { 35, 30, 20 }, { 45, 40, 30 } };        //p[0]=0 甲 岗位 A
            //p[1]=1 乙 岗位 B
            static int[] p = new int[3] { -1, -1, -1 };        static int sum=0;        static void Best(int n)
            {
                if (n <= -1)
                {
                    int s=0;
                    for (int j = 0; j < 3; j++)
                        s += data[j, p[j]];                if (s > sum)
                        sum = s;                return;
                }            for (int i = 0; i < 3; i++)
                {
                    p[n] = i;
                    if (!IsOK(n, p[n]))
                        continue;
                    Best(n - 1);
                }
                //Best(n - 1);
            }        static bool IsOK(int n,int i)
            {
                for (int j = 2; j > n; j--)
                {
                    if (p[j] == i)
                        return false;
                }
                return true;        }        static void Main(string[] args)
            {            Best(2);            Console.WriteLine(sum);            Console.ReadLine();        }
        }
      

  3.   

    不是批评你的意思,要自己动脑筋
    建立一个DataTable 甲乙丙是三条记录,一天记录有4个字段值,人名、A岗位钱、B岗位钱、C岗位钱,对岗位钱的大小进行排序,如果岗位多了依次类推,最近将多条记录的最大值相加