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 ...
随机推荐
- 《Airbnb 早期BP》---创业学习--训练营直播第3课--HHR
1,Airbnb:300亿美金. 一,BP 价值: 1,优秀的BP原则: (1)UCD原则:user centered design,用户为中心的设计.站在投资人视角,回答最关心的问题. (2)清晰原 ...
- Fizz Buzz in tensorflow
code from keras.layers.normalization import BatchNormalization from keras.models import Sequential f ...
- 三 模拟实现顺序表ArrayList
/** * 顺序表,重点是数组动态扩容,插入 * 底层采用数组,长度可以动态变化,此处采用增长一倍 * java.util.ArrayList每次增长50% * int newCapacity = ...
- java 作业11.4
package text3; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import ...
- 什么是SOA架构
什么是SOA架构 SOA是Service-Oriented Architecture的首字母简称,它是一种支持面向服务的架构样式.从服务.基于服务开发和服务的结果来看,面向服务是一种思考方式.其实SO ...
- i.MX RT600之DSP开发环境调试篇
i.MX RT600的Cadence Xtensa HiFi 4 Audio DSP 是一个高度优化过的音频处理器,主频高达600MHz,专门为音频信号的编码.解码以及预处理和后处理模块而设计,功能十 ...
- idea修改项目编码
- iOS开发应用上架必读最新苹果审核规则(史上最全版)
官方文档 地址https://developer.apple.com/cn/app-store/review/guidelines/ App Store 审核指南 简介 App 正在改变世界,丰富人们 ...
- 机器学习之SVM多分类
实验要求数据说明 :数据集data4train.mat是一个2*150的矩阵,代表了150个样本,每个样本具有两维特征,其类标在truelabel.mat文件中,trainning sample 图展 ...
- Codeforces #617 (Div. 3) D. Fight with Monsters(贪心,排序)
There are nn monsters standing in a row numbered from 11 to nn . The ii -th monster has hihi health ...