| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11920 | Matrix Chain Multiplication |
|
| 12224 | Doubly Linked List |
|
Description
**[2018/5/12 02:12 PM] : Sorry for the confusion (get_row, get_col) in the original code! The partial code provided has been improved for clarity and all submissions to this problem has been rejudged! For new submissions, please check out the new partial code! Sincerely apologize for the inconvenience caused!**
There are few Matrix stored in MatrixChain Class , please implement the calc function to get chain multiplication of them.
Your task is to implement the following three functions:
Matrix Matrix::operator*(const Matrix &a) const
Matrix Matrix::operator=(const Matrix &a)
Matrix MatrixChain::calc(int l, int r) const
Definition of Chain Multiplication: Given l, r and an array arr of matrices, calculate the result matrix of arr[l] * arr[l+1] * ... * arr[r-1]
Hint : Σ(A[r][k] * B[k][c]) = C[r][c], where C is a matrix with r rows and c columns.
Input
Input will be done by main.cpp so don't worried about it
int T means T matrices
for T : 0 < T < 11
then T matrices with row , col , and each of elements value
for row , col: 0 < row , col < 11
for value of Matrix elements: 0 < value < 11
Finally, give l, r to get the calc() function's answer.
Output
output will also be done by main.cpp so don't worried about it
it will output the calc function's answer .
Sample Input Download
Sample Output Download
Partial Judge Code
11920.cppPartial Judge Header
11920.hTags
Discuss
Description
Maintain a doubly linked list, which supports the following operations:
(1) IH i : Insert a new integer i to the head of the list.
(2) IT i : Insert a new integer i to the tail of the list.
(3) RH : Print and remove the element in the head of the list. If the list is empty, print a blank line.
(4) RT : Print and remove the element in the tail of the list. If the list is empty, print a blank line.
(5) S : Swap the first floor(k/2) elements and the last k - floor(k/2) elements, where k is the total number of elements in the list. For example, if k = 5, the result of swapping a1, a2, a3, a4, a5 will be a3, a4, a5, a1, a2.
To improve the performance, it is suggested that three pointers be maintained in case4: head, tail and middle, where middle points to the floor(k/2) + 1-th element. With the help of these pointers, all of the operations can be done in constant time.
Input
There is only a single set of input and each operation will occupy a line. There will be a space between “IH” and “i”, and “IT” and “i”. The input contains OP operations, and it is terminated by end-of-file (EOF). You may assume that i is a nonnegative integer not greater then 100000. The list is initially empty.
For case1 and case2, 1<=OP<=1000
For case3, 1<=OP<=10000, For each S operation, O(n) is also accepted.
For case4 and case5, 1<=OP<=500000, each operation should be done in O(1).
Output
For each “RH” or “RT” operation, print a line containing the removed integer as commanded by the operation.
For RH and RT operation: if the list is empty, print a blank line.