博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj2385(dp)
阅读量:5161 次
发布时间:2019-06-13

本文共 2710 字,大约阅读时间需要 9 分钟。

题目链接:

Apple Catching
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9372   Accepted: 4565

Description

It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, each full of apples. Bessie cannot reach the apples when they are on the tree, so she must wait for them to fall. However, she must catch them in the air since the apples bruise when they hit the ground (and no one wants to eat bruised apples). Bessie is a quick eater, so an apple she does catch is eaten in just a few seconds.  
Each minute, one of the two apple trees drops an apple. Bessie, having much practice, can catch an apple if she is standing under a tree from which one falls. While Bessie can walk between the two trees quickly (in much less than a minute), she can stand under only one tree at any time. Moreover, cows do not get a lot of exercise, so she is not willing to walk back and forth between the trees endlessly (and thus misses some apples).  
Apples fall (one each minute) for T (1 <= T <= 1,000) minutes. Bessie is willing to walk back and forth at most W (1 <= W <= 30) times. Given which tree will drop an apple each minute, determine the maximum number of apples which Bessie can catch. Bessie starts at tree 1.

Input

* Line 1: Two space separated integers: T and W  
* Lines 2..T+1: 1 or 2: the tree that will drop an apple each minute.

Output

* Line 1: The maximum number of apples Bessie can catch without walking more than W times.

Sample Input

7 22112211

Sample Output

6

Hint

INPUT DETAILS:  
Seven apples fall - one from tree 2, then two in a row from tree 1, then two in a row from tree 2, then two in a row from tree 1. Bessie is willing to walk from one tree to the other twice.  
OUTPUT DETAILS:  
Bessie can catch six apples by staying under tree 1 until the first two have dropped, then moving to tree 2 for the next two, then returning back to tree 1 for the final two.

Source

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define ll long longconst double eps = 1e-6;const double pi = acos(-1.0);const int INF = 0x3f3f3f3f;const int MOD = 1000000007;int t,w,x;int f[1005][35],a[1005];int main (){ while (scanf ("%d%d",&t,&w)==2) { memset(f, 0,sizeof(f)); for (int i=1; i<=t; i++) { scanf ("%d",&a[i]); f[i][0] = f[i-1][0]+(a[i]==1?1:0); } for (int j=1; j<=w; j++) { for (int i=1; i<=t; i++) { f[i][j] = max(f[i-1][j], f[i-1][j-1])+(a[i]==(j%2+1)?1:0); } } printf ("%d\n",f[t][w]); } return 0;}

 

转载于:https://www.cnblogs.com/lytwajue/p/7001284.html

你可能感兴趣的文章
h.264加权预测
查看>>
as4 通过yum自动升级实现
查看>>
mimtproxy的使用(windows)
查看>>
学习springMVC实例1——配置和跳转到HelloWorld
查看>>
注解@Slf4j
查看>>
92:Reverse Linked List II翻转链表【链表】
查看>>
JDBC 获取被插入数据的主键ID值
查看>>
new Date()时间对象
查看>>
Tomcat配置SSL连接
查看>>
最短路
查看>>
android--asp.net webservice 返回json
查看>>
javascript实现KMP算法(没啥实用价值,只供学习)
查看>>
洛谷P2324 [SCOI2005]骑士精神
查看>>
Android MVP框架实现登录案例
查看>>
使用全局唯一标识(GUID)
查看>>
题解【poj2774 Long Long Message】
查看>>
beyondCompare试用期到期解决办法
查看>>
成功实施的APS项目故事分享---我们数据治理的心路历程
查看>>
4.2.7 Waiting ten thousand years for Love
查看>>
java concurrent 探秘
查看>>