|
|
|
|
背景 Background |
|
|
为了for beginngers,特设此题,^_^
|
|
|
|
|
|
|
|
描述 Description |
|
|
四、求最大和(100分 存盘程序名:TD.pas)
老师写出一行n个正整数,要求从中选取若干个,但不能选相邻的数,使选取数的和最大。如:从13、18、28、45、21中选取18、45和为63,是最大和。起初呈呈觉得很容易,可后来越想越感到棘手。老师提示:第i个数是否选取,可确定前i个数中的最大和。它可由前i-1个数中的最大和与前i-2个数中的最大和来推算。呈呈立刻开窍,难题迎刃而解!
输入:n (0<n<=50)
n个正整数 (正整数<=300,空格相隔)
输出:最大和
[样例1]
输入:(td.in)
5
13 18 28 45 21
输出:(td.out)
63
[样例2]
输入:(td.in)
6
27 31 26 4 5 30
输出:(td.out)
83
|
|
|
|
|
|
|
|
输入格式 Input Format |
|
|
n(0<n<=50)
n个正整数 (正整数<=300,空格相隔)
|
|
|
|
|
|
|
|
时间限制 Time Limitation |
|
|
各个测试点1s
|
|
|
|
|
|
|
|
注释 Hint |
|
|
Free Pascal Code:
-------------------
program Plus;
var a,b:longint;
begin
readln(a,b);
writeln(a+b);
end.
C++ Code:
-------------------
#include <iostream>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
cout<<a+b<<endl;
return 0;
}
|
|
|
|
|
|
|
|
|
Flag |
|
题号 |
P1099 |
|
其它 |
通过 |
36人 |
提交 |
125次 |
通过率 |
29% |
难度 |
0 |
|
|
|
|
|
|