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 ...
随机推荐
- reduxDevTool 配置
import { createStore, compose, applyMiddleware } from 'redux' import reducer from './reducer' import ...
- Nginx实现HTTP及TCP负载均衡
这种通过一台apache的服务器把客户请求分别传递给两台tomcat叫负载均衡 ========================================= ================= ...
- 「JSOI2011」分特产
「JSOI2011」分特产 传送门 计数题. 考虑容斥掉每人至少一个的限制. 就直接枚举至少有多少人没有分到特产,然后剩下的随便分. \[Ans = \sum_{i = 0}^n (-1)^i {n ...
- javascript对象创建及继承
//****************************************************************************** //创建类的多种方式 //------ ...
- Centos7 [ubuntu] 安装pycharm2019.1.3并永久破解教程
一.安装pycharm2019专业版并激活步骤 1.拉取安装包 # wget https://download.jetbrains.com/python/pycharm-professional- ...
- javascript入门教程02
JavaScript中的运算符 (1)算术运算符 + :相加 var a=123,b=45; document.write(a+b); - :相减 document.write(a-b); *:相乘 ...
- [转]Mysql连表之多对多
转自 回到顶部 连表多对多 可以理解成一夫多妻和一妻多夫. 男人表: nid name 1 xxx 2 yyy 3 zzz 女人表: nid name 1 aaa 2 bbb 3 ccc 要让两个表建 ...
- 5-3 使用antDesign的form组件
import { Form, Icon, Input, Button, Checkbox } from 'antd'; class NormalLoginForm extends React.Comp ...
- Struts2学习(四)
struts-defualt.xml指定的result的类型 1.struts-defualt.xml 文件的 181 行 开始定义了: <result-types> <result ...
- 【转】CGI 和 FastCGI 协议的运行原理
介绍 深入CGI协议 CGI的运行原理 CGI协议的缺陷 深入FastCGI协议 FastCGI协议运行原理 为什么是 FastCGI 而非 CGI 协议 CGI 与 FastCGI 架构 再看 Fa ...