A-Apple Catching(POJ 2385)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 8759 | Accepted: 4264 |
Description
Each minute, one of the two apple trees drops an apple. Bessie, having much practice, can catch an apple if she is standing under a tree from which one falls. While Bessie can walk between the two trees quickly (in much less than a minute), she can stand under only one tree at any time. Moreover, cows do not get a lot of exercise, so she is not willing to walk back and forth between the trees endlessly (and thus misses some apples).
Apples fall (one each minute) for T (1 <= T <= 1,000) minutes. Bessie is willing to walk back and forth at most W (1 <= W <= 30) times. Given which tree will drop an apple each minute, determine the maximum number of apples which Bessie can catch. Bessie starts at tree 1.
Input
* Lines 2..T+1: 1 or 2: the tree that will drop an apple each minute.
Output
Sample Input
7 2
2
1
1
2
2
1
1
Sample Output
6
Hint
Seven apples fall - one from tree 2, then two in a row from tree 1, then two in a row from tree 2, then two in a row from tree 1. Bessie is willing to walk from one tree to the other twice.
OUTPUT DETAILS:
Bessie can catch six apples by staying under tree 1 until the first two have dropped, then moving to tree 2 for the next two, then returning back to tree 1 for the final two.
Source
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define MAXN 1005
int d[MAXN][][];
int tree[MAXN];
int main()
{
int t, w;
memset(d, , sizeof(d));
scanf("%d%d", &t, &w);
for(int i = ; i <= t; i++) {
scanf("%d", &tree[i]);
tree[i]--;
}
for(int i = ; i <= t; i++) {
d[i][][tree[i]] = d[i - ][][tree[i]] + ,
d[i][][!tree[i]] = d[i - ][][!tree[i]];
for(int j = ; j <= w; j++)
d[i][j][tree[i]] = max(d[i - ][j - ][!tree[i]], d[i - ][j][tree[i]]) + ,
d[i][j][!tree[i]] = d[i - ][j][!tree[i]];
}
int maxn = -;
for(int i = ; i <= w; i++) maxn = max(maxn, max(d[t][i][], d[t][i][]));
printf("%d", maxn);
return ;
}
最新文章
- Swift-数组
- 《Note --- Unreal 4 --- behavior tree》
- ViewHolder优化2>;:
- Vue-router中文教程-Vue-router参考手册.CHM
- Win8 WinRT将替换Win32 API程序员何去何从?
- 剑指offer习题集2
- Machine Learning for hackers读书笔记(二)数据分析
- XCode中的特殊快捷键图标
- angular 控制器之间值得传递
- C#格式化成小数
- Spring+SpringMVC+MyBatis+easyUI整合优化篇(三)代码测试
- WCF(一)基础整理
- 十年磨一剑 Delphi重新崛起再写传奇
- Centos7_64环境搭建
- Windows 性能监视器的基本指标说明(CPU,内存,硬盘参数)
- C#Windows Service程序的创建安装与卸载
- B - Pie
- MySQL乐观锁和悲观锁的概念和原理
- 去除图像中的alpha通道或透明度
- poi 导入Excel解析 2003 2007