Apple Catching(dp)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 9831 | Accepted: 4779 |
Description
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
* Lines 2..T+1: 1 or 2: the tree that will drop an apple each minute.
Output
Sample Input
7 2
2
1
1
2
2
1
1
Sample Output
6
Hint
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.
dp[j][i]=max(dp[j-1][i-1],dp[j][i-1])+x-1;
else
dp[j][i]=max(dp[j-1][i-1],dp[j][i-1])+(x&1);
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define P_ printf(" ");
#define puts puts("");
typedef long long LL;
const int MAXN=1010;
int dp[35][MAXN];
int main(){
int T,W;
while(~scanf("%d%d",&T,&W)){
mem(dp,0);
int x;
for(int i=1;i<=T;i++){
SI(x);
dp[0][i]=dp[0][i-1]+(x&1);
for(int j=1;j<=W;j++){
if(j&1)
dp[j][i]=max(dp[j-1][i-1],dp[j][i-1])+x-1;
else
dp[j][i]=max(dp[j-1][i-1],dp[j][i-1])+(x&1);
}
}
int ans=0;
for(int i=0;i<=W;i++)ans=max(ans,dp[i][T]);
printf("%d\n",ans);
}
return 0;
}
Apple Catching(dp)的更多相关文章
- poj 2385 Apple Catching(dp)
Description It and ) in his field, each full of apples. Bessie cannot reach the apples when they are ...
- BZOJ 3384: [Usaco2004 Nov]Apple Catching 接苹果( dp )
dp dp( x , k ) = max( dp( x - 1 , k - 1 ) + *** , dp( x - 1 , k ) + *** ) *** = 0 or 1 ,根据情况 (BZOJ 1 ...
- poj 2385 Apple Catching 基础dp
Apple Catching Description It is a little known fact that cows love apples. Farmer John has two ap ...
- 【POJ】2385 Apple Catching(dp)
Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13447 Accepted: 6549 D ...
- poj2385 Apple Catching (线性dp)
题目传送门 Apple Catching Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 154 ...
- POJ 2385 Apple Catching【DP】
题意:2棵苹果树在T分钟内每分钟随机由某一棵苹果树掉下一个苹果,奶牛站在树#1下等着吃苹果,它最多愿意移动W次,问它最多能吃到几个苹果.思路:不妨按时间来思考,一给定时刻i,转移次数已知为j, 则它只 ...
- Apple Catching(POJ 2385)
Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9978 Accepted: 4839 De ...
- 3384/1750: [Usaco2004 Nov]Apple Catching 接苹果
3384/1750: [Usaco2004 Nov]Apple Catching 接苹果 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 18 Solv ...
- bzoj 3384: [Usaco2004 Nov]Apple Catching 接苹果
双倍经验题... -->1750 dp!! 3384: [Usaco2004 Nov]Apple Catching 接苹果 Time Limit: 1 Sec Memory Limit: 12 ...
随机推荐
- Android:res之selector背景选择器
selector根据不同的选定状态来定义不同的现实效果 常用属性: android:state_selected--------选中android:state_focused--------获得焦点a ...
- org.gradle.process.internal.ExecException:
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ...
- MVC3 分页Helper
利用mvc3实现分页效果.效果图如下: 直接拷代码: 首页添加一个Helper的类(命名空间为System.Web.Mvc;). public static HtmlString ShowPageNa ...
- 19.java.lang.NoClassDefFoundException
java.lang.NoClassDefFoundException未找到类定义错误 当Java虚拟机或者类装载器试图实例化某个类,而找不到该类的定义时抛出该错误. 违背安全原则异常:Secturit ...
- Open source and free log analysis and log management tools.
Open source and free log analysis and log management tools. Maintained by Dr. Anton Chuvakin Version ...
- 使用WinSetupFromUSB来U盘安装windowsXP(不使用win PE系统)
目前用U盘安装XP的多数方法都要借助WINPE,比较麻烦.使用WinSetupFromUSB只需要下载一个6.5MB的绿色软件就可以制作好windows xp的安装U盘,方便简捷. WinSetupF ...
- 搭建Android开发环境之——Android4.0.3, 4.1, 4.2, 4.3, 4.x,及升级 ADT(22.0.5)和SDK(22.x)
1.首先要下载相关的软件 1). JDK 6 以上 2). eclipse( Version 3.6.2 or higher ) 点击下载 3). SDK(android-sdk_r18-windo ...
- C语言入门(3)——对Hello World程序的解释
上篇我们写了一个最简单的程序.这个简单的程序包含了很多重要的内容.本篇我们通过这个最简单的Hello World程序逐一讲解C语言程序的一些特点. 打开Visual Studio 2013 通过菜单- ...
- spring mvc 建立下拉框并进行验证demo
原文出处:http://howtodoinjava.com/spring/spring-mvc/spring-mvc-populate-and-validate-dropdown-example/ 该 ...
- extend vg(pv,lv)use HotPlug Storage PV for VMI(ECC Env)
Preface: 前期存储未规划好,业务快速扩展,数据高安全需求(异地,More one copy),需求多多?NM干着干着活就会时不时的坑爹起来了!particularly Real Product ...