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 ...
随机推荐
- Nginx修改配置实现图片防盗链
一般情况下,防盗链是针对软件下载和图片的,由于一般的站点不提供资源下载,所以本文主要是针对图片的防盗链 1.如果对全站图片做防盗链,至少需要一个另外的域名存放指向图片.因为如果对全站图片做了防盗链,包 ...
- 一个简单的php函数调用实例
需求分析: funcs.php (这个文件,我们定义了一个函数) <?php //我们一个计算,+ - * / 的代码集合->函数 //1. function 是一个关键字 //2. ji ...
- TLC是什么
TLC = Triple-Level Cell,即3bit/cell,它的寿命短,速度慢,约500-5000次擦写寿命. 现在U盘多为MLC,TLC也有一部分,将来TLC会占大部分市场. 一种名为TL ...
- 柯南君:看大数据时代下的IT架构(9)消息队列之RabbitMQ--案例(RPC起航)
二.Remote procedure call (RPC)(using the Java client) 三.Client interface(客户端接口) 为了展示一个RPC服务是如何使用的,我们将 ...
- MFC DLL资源动态切换
在MFC使用过程中,遇到DLL资源与主EXE资源冲突问题. 出现这样的Bug,一时无从下手. 报错位置在核心代码中dlgcore.cpp. [cpp] view plaincopy BOOL AFXA ...
- MySQL数据处理函数
数据处理函数 有时从数据库表中获取到的数据须要进行一些处理. 如将小写字母替换为对应的大写字母.这个处理过程能够在客户机上进行.也能够在数据库上进行. 数据库上进行会更高效.数据库中有对应的数据处理函 ...
- CSS中的 REM PX EM
px像素(Pixel).相对长度单位.像素px是相对于显示器屏幕分辨率而言的 em是相对长度单位.相对于当前对象内文本的字体尺寸.如当前对行内文本的字体尺寸未被人为设置,则相对于浏览器的默认字体尺寸. ...
- Nio Client
public class NIOClient { static int SIZE = 2; final static int bufferSize = 500 * 1024; static InetS ...
- javascript封装自定义滚动条方法,可自定义四个边框滚动条
还是根据我的个人习惯封装了一个方法 setScroll({ box :父盒子DOM对象, content : 内容盒子DOM对象, scrollall : 滚动条大盒子DOM对象, scroll : ...
- 保存属性至xml并读取
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import ja ...