Advertisement
svetlai

CardGame

Nov 20th, 2015
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. namespace CardGame
  2. {
  3.     using System;
  4.     using System.Linq;
  5.  
  6.     public class Program
  7.     {
  8.         public static void Main()
  9.         {
  10.             int n = int.Parse(Console.ReadLine());
  11.             int[] numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  12.  
  13.             int[,] dp = new int[n, n];
  14.  
  15.             for (int length = 3; length <= n; length++)
  16.             {
  17.                 for (int i = 0; i <= n - length; i++)
  18.                 {
  19.                     for (int j = i + 1; j < i + length - 1; j++)
  20.                     {
  21.                         int current = dp[i, j] + dp[j, i + length - 1] + numbers[j] * (numbers[i] + numbers[i + length - 1]);
  22.  
  23.                         if (dp[i, i + length - 1] < current)
  24.                         {
  25.                             dp[i, i + length - 1] = current;
  26.                         }
  27.                     }
  28.                 }
  29.             }
  30.  
  31.             Console.WriteLine(dp[0, n - 1]);
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement