题解 | #矩阵乘法计算量估算#
矩阵乘法计算量估算
https://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
var count = int.Parse(Console.ReadLine());
var all = new List<XY>();
for (var i = 0; i < count; i++)
{
var line = Console.ReadLine().Split(" ");
var x = int.Parse(line[0]);
var y = int.Parse(line[1]);
all.Add(new XY {X = x, Y = y});
}
var all1 = new List<XY>();
var last = Console.ReadLine().ToList();
var pointer = 0;
var result = 0;
for(var i = 0; i< last.Count; i++)
{
if (last[i] == '(')
{
continue;
}
if(last[i] == ')')
{
var length = all1.Count;
var x = all1[length - 2].X;
var y = all1[length - 1].Y;
result += all1[length - 1].X * all1[length - 1].Y * all1[length - 2].X;
all1.RemoveAt(all1.Count - 1);
all1.RemoveAt(all1.Count - 1);
all1.Add(new XY {X = x, Y = y});
}
else
{
all1.Add(all[pointer]);
pointer++;
}
}
Console.WriteLine(result);
}
public class XY
{
public int X;
public int Y;
}
}