Matrix Fetch Game

Source: Internet
Author: User

"Title description"

Handsome often play with classmates a matrix take number game: for a given n*m matrix, each element of the matrix A[i,j] are
is a non-negative integer. The rules of the game are as follows:
1. Each fetch must take one element from each row, a total of n. After M times, all elements of the matrix are taken out;
2. Each element taken away can only be the beginning or end of the line where the element is located;
3. Each fetch has a score value, the sum of the scores for each row, the number of points per row = The value of the element taken away *2^i,
Where I is the number of times I fetch (numbering starting from 1);
4. The end of the game must be divided into M-time score of the sum.
Handsome want to ask you to help write a program, for any matrix, you can find out the maximum score after the number.

"Input description"

1th Act two integers separated by spaces N and M.
The 2nd to n+1 behavior n*m matrix, where each row has m a non-negative integer separated by a single space.

"Output description"

Contains only 1 rows, an integer, which is the maximum score after the input matrix is taken.

"Sample Input"

2 3
1 2 3
3 4 2

"Sample Output"

82

"Data range and Tips"

Sample explanation:

1th time: The 1th row takes the beginning element, the 2nd line takes the line tail element, this time the score is 1*2^1+2*2^1=6;
2nd time: Both lines take the beginning of the element, the score is 2*2^2+3*2^2=20;
3rd time: Score is 3*2^3+4*2^3=56. Must be divided into 6+20+56=82.

60% of the data meet: 1 <= n,m <= 30, the answer is not more than 10^16;
100% data satisfies: 1 <= n,m <= 80,0 <= a[i,j] <= 1000.

Matrix Fetch Games

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.