You are in the world of mathematics to solve the great "Monkey Banana Problem". It states that, a monkey enters into a diamond shaped two dimensional array and can jump in any of the adjacent cells down from its current position (see figure). While moving from one cell to another, the monkey eats all the bananas kept in that cell. The monkey enters into the array from the upper part and goes out through the lower part. Find the maximum number of bananas the monkey can eat.
Input starts with an integer T (≤ 50), denoting the number of test cases.
Every case starts with an integer N (1 ≤ N ≤ 100)<喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vc3Ryb25nPi4gSXQgZGVub3RlcyB0aGF0LCB0aGVyZSB3aWxsIGJlIDxzdHJvbmc+MipOIC0gMTwvc3Ryb25nPiByb3dzLiBUaGUgPHN0cm9uZz5pPHN1cD50aDwvc3VwPiAoMSCh3CBpIKHcIE4pPC9zdHJvbmc+IGxpbmUgb2YgbmV4dCA8c3Ryb25nPk48L3N0cm9uZz4gbGluZXMgY29udGFpbnMgZXhhY3RseSA8c3Ryb25nPmk8L3N0cm9uZz4gbnVtYmVycy4KIFRoZW4gdGhlcmUgd2lsbCBiZSA8c3Ryb25nPk4gLSAxPC9zdHJvbmc+IGxpbmVzLiBUaGUgPHN0cm9uZz5qPHN1cD50aDwvc3VwPiAoMSCh3CBqIDwgTik8L3N0cm9uZz4gbGluZSBjb250YWlucyA8c3Ryb25nPk4gLSBqPC9zdHJvbmc+IGludGVnZXJzLiBFYWNoIG51bWJlciBpcyBncmVhdGVyIHRoYW4gemVybyBhbmQgbGVzcyB0aGFuIDxzdHJvbmc+MjxzdXA+MTU8L3N1cD48L3N0cm9uZz4uPC9wPgo8aDE+T3V0cHV0PC9oMT4KPHA+Rm9yIGVhY2ggY2FzZSwgcHJpbnQgdGhlIGNhc2UgbnVtYmVyIGFuZCBtYXhpbXVtIG51bWJlciBvZiBiYW5hbmFzIGVhdGVuIGJ5IHRoZSBtb25rZXkuPC9wPgo8dGFibGUgYm9yZGVyPQ=="1" cellspacing="0" cellpadding="0">
2 4 7 6 4 2 5 10 9 8 12 2 2 12 7 8 2 10 2 1 2 3 1 Case 1: 63 Case 2: 5 三角形塔題目的加強版,這次是上下兩個顛倒的三角形疊加一起了。 結果我下標沒注意,要調試了很長時間,反復強調下標的精確性了。 方法也是從底往上:只有一條數組的時候,必然是從中選擇最大的一個數,有兩條數組的時候,那麼就是從上一條走到下一條,當前數組的一個格子的數選擇可以走到下一個數組的數,這裡是兩個選擇,的最大值加起來。如此從底往上推導,就能出結果了。 不要問我算法有什麼用了: 就自娛自樂吧。 小公司是根本用不上的,或者說他們根本沒有懂算法的人在裡面,也就更加不會有懂算法的人出來當面試官,招懂算法的人了。 算法是屠龍刀,問題是先要找到龍。Sample Input
Output for Sample Input
#include