hdu4719¡ª¡ªOh My Holy FFF
Oh My Holy FFF
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 626 Accepted Submission(s): 147
Problem Description
N soldiers from the famous "*FFF* army" is standing in a line, from left to right.
o o o o o o o o o o o o o o o o o o
/F\ /F\ /F\ /F\ /F\ /F\ /F\ /F\ /F\ /F\ /F\ /F\ /F\ /F\ /F\ /F\ /F\ /F\
/ \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \
You, as the captain of *FFF*, want to divide them into smaller groups, but each group should still be continous in the original line. Like this:
o o o | o o o o | o o o o o o | o o o o o
/F\ /F\ /F\ | /F\ /F\ /F\ /F\ | /F\ /F\ /F\ /F\ /F\ /F\ | /F\ /F\ /F\ /F\ /F\
/ \ / \ / \ | / \ / \ / \ / \ | / \ / \ / \ / \ / \ / \ | / \ / \ / \ / \ / \
In your opinion, the number of soldiers in each group should be no more than L.
Meanwhile, you want your division be "holy". Since the soldier may have different heights, you decide that for each group except the first one, its last soldier(which is the rightmost one) should be strictly taller than the previous group's last soldier. That
is, if we set bi as the height of the last soldier in group i. Then for i >= 2, there should be b
i > b
i-1.
You give your division a score, which is calculated as
, b
0 = 0 and 1 <= k <= M, if there are M groups in total. Note that M can equal to 1.
Given the heights of all soldiers, please tell us the best score you can get, Z†·Ÿ"http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vciBkZWNsYXJlIHRoZSBkaXZpc2lvbiBhcyBpbXBvc3NpYmxlLgogCjxicj4KSW5wdXQKVGhlIGZpcnN0IGxpbmUgaGFzIGEgbnVtYmVyIFQgKFQgPD0gMTApICwgaW5kaWNhdGluZyB0aGUgbnVtYmVyIG9mIHRlc3QgY2FzZXMuPGJyPgpGb3IgZWFjaCB0ZXN0IGNhc2UsIGZpcnN0IGxpbmUgaGFzIHR3byBudW1iZXJzIE4gYW5kIEwgKDEgPD0gTCA8PSBOIDw9IDEwPHN1cD41PC9zdXA+KSwgYXMgZGVzY3JpYmVkIGFib3ZlLjxicj4KVGhlbiBjb21lcyBhIHNpbmdsZSBsaW5lIHdpdGggTiBudW1iZXJzLCBmcm9tIEgxIHRvIEhuLCB0aGV5IGFyZSB0aGUgaGVpZ2h0IG9mIGVhY2ggc29sZGllciBpbiB0aGUgbGluZSwgZnJvbSBsZWZ0IHRvIHJpZ2h0LiAoMSA8PSBIPHN1Yj5pPC9zdWI+IDw9IDEwPHN1cD41PC9zdXA+KQogCjxicj4KT3V0cHV0CkZvciB0ZXN0IGNhc2UgWCwgb3V0cHV0IA=="Case #X: " first, then output the best score.
Sample Input
2
5 2
1 4 3 2 5
5 2
5 4 3 2 1
Sample Output
Case #1: 31
Case #2: No solution
Source
2013 ACM/ICPC Asia Regional Online ¡ª¡ª Warmup2
Recommend
Ï߶ÎÊ÷dp
dp[i] = max(dp[j] - arr[j] + arr[i] * arr[i])
ÕâÌâÐèÒª´ÓСµÄ¿ªÊ¼´¦Àí£¬ÒòΪСµÄ²»ÊÜ´óµÄÓ°Ï죬ËùÒÔÏÈ´¦Àíû¹Øϵ£¬µ«ÊÇÈç¹ûÓöµ½ÓÐÏàͬµÄ¸ß¶ÈµÄµãj, iʱ£¬ÎÒÃÇÐèÒªÏÈ´¦ÀíÅÅÔÚºóÃæµÄi£¬ÒòΪÈç¹ûÏÈ´¦ÀíÇ°ÃæµÄj£¬¶øÇҺܲ»ÇɸպÃjÓÐ×î´ó值£¬ÄÇô´¦ÀíiµÄʱºò¾Í»á²éµ½ÄǸö值£¬µ«ÊÇÕâÆäʵÊÇ·Ç·¨µÄ£»·´Ö®ÎÒÃÇÏÈ´¦ÀíºóÃæµÄi£¬´ËʱjûÓвåÈëµ½Ï߶ÎÊ÷ÉÏ£¬ËùÒÔi²»ÊÜÓ°Ï죬¶ø´¦ÀíÇ°ÃæµÄjµÄʱºò£¬Ò²ÊÇÍù×óÕÒ£¬ËùÒÔ²»ÊܺóÃæµÄiµÄÓ°Ï죬²éѯµÄʱºòÖ»Òª±£Ö¤²éѯÇø¼ä³¤¶È²»´óÓëd¾ÍÐÐÁË
#include