Day9 - A - Apple Catching POJ - 2385
Description
有两棵APP树,编号为1,2.每一秒,这两棵APP树中的其中一棵会掉一个APP.每一秒,你可以选择在当前APP树下接APP,或者迅速移动到另外一棵APP树下接APP(移动时间可以忽略不计),但由于却乏锻炼,你最多移动W次.问在T秒内,你最多能收集多少个APP.假设你开始站在1号APP树下.
Input
第1行:两个整数T(1 < = T< = 1000)和W(1 < = W< = 30)
第2..T+1行:1或2,代表每分钟掉落APP的那棵树的编号
Output
一行一个整数,代表你移动不超过W次能接住的最大APP数
Sample Input
7 2
2
1
1
2
2
1
1
Sample Output
6 思路:简单的dp,设状态转移为dp[i][j],第i秒,移动了j次,能抓住的APP为dp[i][j],对于每次j,有两种状态:苹果在该位置,苹果不在该位置,若苹果在该位置,dp[i][j]=max(dp[i-1][j],dp[i-1][j-1])+1,若苹果不在该位置,dp[i][j]=max(dp[i-1][j],dp[i-1][j-1]),再使用滚动数组压缩即可
int dp[];
int main() {
ios::sync_with_stdio(false), cin.tie();
int T, W, val;
cin >> T >> W;
for(int i = ; i <= T; ++i) {
cin >> val;
for(int j = W; j >= ; --j) {
if((j+)% == (val%)) dp[j] = max(dp[j], dp[j-]) +;
else dp[j] = max(dp[j], dp[j-]);
}
}
int ans = ;
for(int i = ; i <= W; ++i)
ans = max(ans, dp[i]);
cout << ans << "\n";
return ;
}
Day9 - A - Apple Catching POJ - 2385的更多相关文章
- DP:Apple Catching(POJ 2385)
牛如何吃苹果 问题大意:一个叫Bessie的牛,可以吃苹果,然后有两棵树,树上苹果每分钟会掉一个,这只牛一分钟可以在两棵树中往返吃苹果(且不吃地上的),然后折返只能是有限次W,问你这只叫Bessie的 ...
- A-Apple Catching(POJ 2385)
Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8759 Accepted: 4264 De ...
- Apple Catching(POJ 2385)
Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9978 Accepted: 4839 De ...
- 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 ...
- 【POJ - 2385】Apple Catching(动态规划)
Apple Catching 直接翻译了 Descriptions 有两棵APP树,编号为1,2.每一秒,这两棵APP树中的其中一棵会掉一个APP.每一秒,你可以选择在当前APP树下接APP,或者迅速 ...
- poj 2385【动态规划】
poj 2385 Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14007 Accepte ...
- Apple Catching(dp)
Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9831 Accepted: 4779 De ...
- 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 ...
随机推荐
- Java Web 笔记(杂)
Java Web 概述 什么是Java Web 在Sun的Java Servlet 规范中,对Java Web 应用做了这样的定义: "Java Web" 应用由一组Servlet ...
- 吴裕雄--天生自然Numpy库学习笔记:NumPy 数学函数
NumPy 包含大量的各种数学运算的函数,包括三角函数,算术运算的函数,复数处理函数等. NumPy 提供了标准的三角函数:sin().cos().tan(). import numpy as np ...
- Oracle常用SQL时间函数
1.查询当前日期和时间 select sysdate from dual; 2.查询本月最后一天 select last_day(sysdate) from dual; 3.查询前后多少月 ) fro ...
- Redis Set操作
public void CleanPur() { var typedClient = _redisClient.As<PurClass>(); typedClient.DeleteAll( ...
- Verilog状态机
以1011为例 代码如下: //1011(Meay型) module state1(clk,in,rst_n,out); input clk; input rst_n; input in; outpu ...
- springMVC读取本地图片显示到前端页面
@RequestMapping("/getImage") @ResponseBody public void getImagesId(HttpServletResponse rp) ...
- Python - python里有类似Java的接口(interface)吗?
参考 https://stackoverflow.com/questions/2124190/how-do-i-implement-interfaces-in-python https://stack ...
- python面试题手动总结答案锦集
数据类型 字符串 1.列举python中的基本数据类型 数字:int 布尔值:bool 字符串:str 列表:list 元组:tuple 字典:dict 集合:set 然后我们需要了解一些运算符,应为 ...
- PAT T1014 Circles of Friends
大水题,dfs判连通块的数量,bfs每个点找朋友圈的最大直径~ #include<bits/stdc++.h> using namespace std; ; vector<int&g ...
- Java记录4--string
1.toString所有的类都默认自动继承了Objiect类 2.Object类中的toString方法返回的时类的名字和该哈希表码组成的一个字符串, System.out.println(类对象名) ...