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 ...
随机推荐
- php传参方式1--ajax
AJAX即“Asynchronous Javascript And XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术. AJAX = 异步 JavaScript和 ...
- CSS自学笔记(6):CSS的模型
CSS 框模型 (Box Model) 规定了元素框处理元素内容.内边距.边框和外边距的方式. 图片来源:w3school.com.cn 元素(element)是一个html文档的实际内容区域,依次由 ...
- (转)设置 UILabel 和 UITextField 的 Padding 或 Insets (理解UIEdgeInsets)
转自http://unmi.cc/uilable-uitextfield-padding-insets 主要是理解下UIEdgeInsets在IOS UI里的意义.靠,这货其实就是间隔,起个名字这么让 ...
- MongoDB 从0开始
MongoDB https://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/ 在Mac上安装 brew update brew i ...
- WPF:构建应用程序
原文 http://www.cnblogs.com/free722/archive/2011/11/13/2247455.html WPF相关的项目内容包含在App.Xaml和Window1.xaml ...
- Codeforces 263E
Codeforces 263E 原题 题目描述:一个\(n \times m\)的矩阵,每格有一个数,给出一个整数\(k\),定义函数\(f(x, y)\): \[f(x, y)=\sum_{i=1} ...
- poj2405---体积几何
#include <stdio.h> #include <stdlib.h> #include<math.h> #define pi acos(-1) int ma ...
- Wet Shark and Flowers(思维)
C. Wet Shark and Flowers time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- pl sql项目演练--B2C商城项目
项目学习视频下载地址:点击下载 1.注册会员及找回密码模块 }该模块主要功能有注册会员和找回密码 }注册会员:所需信息主要有:登录号.密码.真实姓名.性别.密码问题.密码答案.Email.地址.电 ...
- PHP GUID的生成源码
<?php function guid(){ if (function_exists('com_create_guid')){ return com_create_guid(); }else{ ...