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. 【渗透测试】Squirrelmail远程代码执行漏洞+修复方案

    最近网上有点不太平,爆出各种漏洞,等下会把近期的漏洞复现一下,发出来.安全圈的前辈总是默默的奉献,在这里晚辈们只能站在巨人的肩膀上,跟紧前辈们的步伐,走下去. -------------------- ...

  2. 实现简单HttpServer案例

    <html> <head> <title>第一个表单</title> </head> <body> <pre> me ...

  3. 样式计算的几种方式与兼容写法:getComputedStyle&currentStyle&style

    window.getComputedStyle(element,[string]) 1参为需要获取样式的元素,2参指定伪元素字符串(如“::after”,不需要则为null),设置2参可获取eleme ...

  4. iOS 上通过 802.11k、802.11r 和 802.11v 实现 Wi-Fi 网络漫游

    在 iOS 上通过 802.11k.802.11r 和 802.11v 实现 Wi-Fi 网络漫游 了解 iOS 如何使用 Wi-Fi 网络标准提升客户端漫游性能. iOS 支持在企业级 Wi-Fi ...

  5. 【原】简单shell练习(六)

    1.shell获取进程号并杀掉该进程 kill - $(ps -ef | grep node| grep -v grep | awk '{print $2}') 解析: ps (processStat ...

  6. 通过LAMP部署phpMyAdmin、wordpress(https)、discuz

    1.安装启动LAMP 安装环境: CentOS Linux release 7.5.1804 安装包: # yum -y install httpd php php-mysql mariadb-ser ...

  7. 指令——mdadm

    Mdadm命令详解 Linux内核中有一个md(multiple devices)模块在底层管理RAID设备,它会在应用层给我们提供一个应用程序的工具mdadm ,mdadm是linux下用于创建和管 ...

  8. MySQL忘记密码如何重置

    一]进入服务器下,我用的是centos版本 vim /etc/my.cnf 1 vim[二]找到mysqld的部分然后在下面添加上一句代码,意思是跳过密码直接进入,然后保存退出 skip-grant- ...

  9. Ajax案例

      展示页面jsp: <%@ page language="java" contentType="text/html; charset=utf-8" pa ...

  10. oracle 高级函数

    原 oracle 高级函数 2017年08月17日 16:44:19 阅读数:1731 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u013278 ...