程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> [ACM] hdu 1087 Super Jumping! Jumping! Jumping! (動態規劃)

[ACM] hdu 1087 Super Jumping! Jumping! Jumping! (動態規劃)

編輯:C++入門知識

Super Jumping! Jumping! Jumping!

Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 6 Accepted Submission(s) : 5

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.

\


The game can be played by two Z喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vciBtb3JlIHRoYW4gdHdvIHBsYXllcnMuIEl0IGNvbnNpc3RzIG9mIGEgY2hlc3Nib2FyZKOoxuXFzKOpYW5kIHNvbWUgY2hlc3NtZW6jqMbl19OjqSwgYW5kIGFsbCBjaGVzc21lbiBhcmUgbWFya2VkIGJ5IGEgcG9zaXRpdmUgaW50ZWdlciBvciChsHN0YXJ0obEgb3IgobBlbmShsS4gVGhlIHBsYXllciBzdGFydHMgZnJvbSBzdGFydC1wb2ludCBhbmQgbXVzdCBqdW1wcyBpbnRvIGVuZC1wb2ludCBmaW5hbGx5LiBJbgogdGhlIGNvdXJzZSBvZiBqdW1waW5nLCB0aGUgcGxheWVyIHdpbGwgdmlzaXQgdGhlIGNoZXNzbWVuIGluIHRoZSBwYXRoLCBidXQgZXZlcnlvbmUgbXVzdCBqdW1wcyBmcm9tIG9uZSBjaGVzc21hbiB0byBhbm90aGVyIGFic29sdXRlbHkgYmlnZ2VyICh5b3UgY2FuIGFzc3VtZSBzdGFydC1wb2ludCBpcyBhIG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YXNlIHN0YXJ0aW5nIHdpdGggMCB0ZXJtaW5hdGVzIHRoZSBpbnB1dCBhbmQgdGhpcyB0ZXN0IGNhc2UgaXMgbm90IHRvIGJlIHByb2Nlc3NlZC48YnI+Cgo8cD4gPC9wPgo8aDM+T3V0cHV0PC9oMz4KPHA+IDwvcD4KRm9yIGVhY2ggY2FzZSwgcHJpbnQgdGhlIG1heGltdW0gYWNjb3JkaW5nIHRvIHJ1bGVzLCBhbmQgb25lIGxpbmUgb25lIGNhc2UuPGJyPgoKPHA+IDwvcD4KPGgzPlNhbXBsZSBJbnB1dDwvaDM+CjxwPiA8L3A+Cgo8cHJlIGNsYXNzPQ=="brush:java;">3 1 3 2 4 1 2 3 4 4 3 3 2 1 0

Sample Output

4
10
3

Author

lcy

解題思路:

類似最長遞增子序列的想法,只不過這裡求的是到第i個元素時,最長遞增子序列,各個元素的和。求最大的那個值。

代碼:

#include 
#include 
#include 
using namespace std;
const int maxn=1002;
int num[maxn];
int sum[maxn];
int n;

int main()
{
    while(scanf("%d",&n)!=EOF&&n)
    {
        for(int i=1;i<=n;i++)
            scanf("%d",&num[i]);
        sum[1]=num[1];
        int ans=sum[1];
        for(int i=2;i<=n;i++)
        {
            sum[i]=num[i];
            for(int j=1;jsum[i])//滿足遞增且當前的sum[i]小與前面中的sum[j]+當前的數
                    sum[i]=sum[j]+num[i];//sum[i]為最長遞增子序列的和,當前num[i]必選。
            }
            if(ans


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved