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的更多相关文章

  1. DP:Apple Catching(POJ 2385)

    牛如何吃苹果 问题大意:一个叫Bessie的牛,可以吃苹果,然后有两棵树,树上苹果每分钟会掉一个,这只牛一分钟可以在两棵树中往返吃苹果(且不吃地上的),然后折返只能是有限次W,问你这只叫Bessie的 ...

  2. A-Apple Catching(POJ 2385)

    Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8759   Accepted: 4264 De ...

  3. Apple Catching(POJ 2385)

    Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9978   Accepted: 4839 De ...

  4. poj 2385 Apple Catching 基础dp

    Apple Catching   Description It is a little known fact that cows love apples. Farmer John has two ap ...

  5. 【POJ】2385 Apple Catching(dp)

    Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13447   Accepted: 6549 D ...

  6. 【POJ - 2385】Apple Catching(动态规划)

    Apple Catching 直接翻译了 Descriptions 有两棵APP树,编号为1,2.每一秒,这两棵APP树中的其中一棵会掉一个APP.每一秒,你可以选择在当前APP树下接APP,或者迅速 ...

  7. poj 2385【动态规划】

    poj 2385 Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14007   Accepte ...

  8. Apple Catching(dp)

    Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9831   Accepted: 4779 De ...

  9. 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 ...

随机推荐

  1. 拓扑排序板子 hihocoder-1174

    思路 不断删入度为1的点及其出边. 图解 #include <bits/stdc++.h> using namespace std; const int maxn=1e5+10; vect ...

  2. mybatis用mybatis-generator-core-1.3.5.jar自动生成实体类

    原文出处:https://blog.csdn.net/shuoshuo_12345/article/details/80626241,本文只是个人总结而已! 方法1:在pom文件中添加依赖 只需在搭建 ...

  3. Docker 安装 Kibana

    使用和 elasticsearch 相同版本镜像 7.4.1 (不一样可能会出现问题) 1.下载Kibana镜像  # 下载Kibana镜像 docker pull kibana: # 查看镜像 do ...

  4. pip-9.0.1更新到pip-10.0.1遇到的问题

    使用 pip 安装第三方库时,报错: You are using pip version 9.0.3, however version 10.0.1 is available. You should ...

  5. python--脚本传参与shell脚本传参(位置参数)

    写一个最简单的shell脚本,了解shell脚本是如何传参 1. vim test1.sh name=$1 age=$2 echo ${name} echo ${age} 2.调用脚本并传参 sh t ...

  6. 定时任务--mysql数据库备份

    vim /home/back.sh #!/bin/bash USER="******" PASSWORD="******" DATABASE="*** ...

  7. oracle的decode、sign、nvl,case...then函数

    ORACLE几种常用的方法 1.decode 常见的用法 : 格式:decode(condition,value1,result[, value2,result2], default_result) ...

  8. Plastic Sprayers Manufacturer - Spray Principle, Spray Note

    The     Plastic Sprayers Manufacturer    stated that the spray is artificial fogging. Simply put, th ...

  9. leetcode刷题-- 2. 排序(待更新)

    排序 参考五分钟学算法 复杂度比较 时间复杂度 O(n2) 各种简单的排序:直接插入.直接选择.冒泡 O(nlog2n) 快速排序.堆排序.归并排序 O(n1+\(\lambda\)),希尔排序 线性 ...

  10. Django问题 Did you rename .....a ForeignKey

    给新加入的字段添加一个default默认值即可,让字段非空.然后在进行makemigrations,完成操作后删除相关默认值即可.