Apple Tree(动态规划)
来源:互联网 发布:怎样才能在淘宝上开店 编辑:程序博客网 时间:2024/05/22 03:26
Apple Tree
Time Limit: 10 Second Memory Limit: 32768 KB
Description
There are so many problems called “Apple Tree”, including the one you are reading now.
After Leilei goes back home, he finds that all his grandpa’s apple trees go ripe. He is so happy and wants to pick some apples back to his school and shares them with all his friends, including the ones in the ACM group. Assume all the trees are in a line. To stop Leilei from picking all the apples, his grandpa asks him not to pick from two trees in K consecutive trees. So Leilei asks you, a genius programmer, to help him find out how many apples could he pick at most.
Input
There are multiple test cases.
In the first line of each test case there is only one integer N, indicating the number of grandpa’s apple trees. Here 0<N<=100000. A line with N=0 indicating the end of the input file.
In the second line of each test case there is only one positive integer K, which is described above.
In the next N lines there is one integer Ai per line, which is the number of apples in the ith tree. Here 0<Ai<=100.
Output
For each case, output one line with only one number which is the maximum apples Leilei can pick.
Sample Input
5
2
1
2
3
4
5
3
3
10
10
10
0
Sample Output
9
10
题目大意:
在一序列数中,每连续K个数最多取一个数,使取到的数的和最大,输出和。
思路:
a[i]保存序列的数。
b[i]保存前i个数能取到的最大的和。
b[i]=max(a[i],b[i-1])=max(a[0],a[1],…a[i]). i<k
b[i]=max(a[i]+b[i-k],b[i-1]). i>=k
- Apple Tree(动态规划)
- 简单树形动态规划(Ural 1018 Binary Apple Tree)
- pku2385 Apple Catching (动态规划)
- POJ2385 Apple Catching 动态规划
- 【动态规划】poj2385 Apple Catching
- poj Apple Catching(动态规划)
- Sicily 1019 Apple Tree (SOJ 1019)【树形dp 树形动态规划】
- POJ2385 Apple Catching——动态规划
- POJ - 2385 Apple Catching(动态规划)
- 1750: [Usaco2005 qua]Apple Catching (动态规划)
- poj 2385 Apple Catching(动态规划)
- POJ2385——Apple Catching(动态规划)
- POJ 2385 Apple Catching 动态规划
- Apple Tree
- Apple Tree
- Apple Tree
- Apple Tree
- Apple Tree
- mysql 连接超时解决方法
- hibernate学习笔记1(javax.persistence.Cacheable)
- 异步操作(二)
- POJ_2531_dfs
- JavaScript层移动关键代码
- Apple Tree(动态规划)
- 在9530手机上面,如何控制程序只能纵向显示?如何判断当前的屏幕横纵方向呢?
- cin.get()与cin.getline()的区别
- ASP.NET实现增删改查等功能(Access版)
- [zz]一个超级简单的php投票系统,不使用数据库
- JMX架构的了解
- ASP.NET实现增删改查等功能(Access版)系统之一 -前台及数据库webconfig配置
- csdn 两万名内博客
- 黑莓手机如何处理横向显示的请求?