点击这里更换您喜欢的皮肤wtboj 首页
请点击这里登入noios   首页 入门 c++讲义 入门教程视频 金牌教程 入门视频 站务 公告 | 题库 记录 竞测 测试 闯关 作业 排名 团队 讨论 | 换肤 | 登入 注册  
News >>   新增功能:各团队管理员可以发布本团队作业了 ()

From VijosGuest0
求最大和
背景 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,空格相隔)
输出格式 Output Format
  最大和
样例输入 Sample Input
 
样例输出 Sample Output
 
时间限制 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
提交 讨论 题解
 Copyright wtboj © 2005-2006. www.wutuobang.date Powered by wtboj 关于 联系 帮助
 wtboj Information ---- Total Users : 1242 | Online Users / Processes : 0 / 75 | Processed Time : 91 ms | Server Time : 2025/4/27 1:37:09