poj Apple Catching
来源:互联网 发布:条码生成器软件下载 编辑:程序博客网 时间:2024/06/11 16:54
#include <iostream>using namespace std;int a[1001][31]; //a[i][j],第i次,移动j次时捡到最多的苹果数量int max(int a, int b) { //判断大小的函数 return a > b ? a : b;}int main() { int t,w,i,j; while (cin >> t >> w) { memset(a, 0, sizeof(a)); int *time = new int[t+1]; for (i = 1; i <=t; i++) cin >> time[i]; if(time[1]==1) a[1][0] = 1; //若第一个苹果在树1掉落,则a[1][0]=1 else a[1][1] = 1; /* j==0时,即没有移动,一直在树1下面; j!=0时,a[i][j]=max(a[i-1][j],a[i-1][j-1]) 若此时所在树掉了苹果,则再加1。 移动奇数次时,应在树2,此时若树2掉苹果,则+1。故表达式可写成: ···+(j%2!=time[i]%2)*/ for (i = 2; i <= t; i++) { for (j = 0; j <= w&&j<=i; j++) { if (j == 0) a[i][j] = a[i - 1][j] + !(time[i]-1); else a[i][j] = max(a[i-1][j],a[i-1][j-1])+(j%2!=time[i]%2); } } cout << a[t][w] << endl; } return 0;}
阅读全文
0 0
- POJ 2385 Apple Catching
- POJ-2385-Apple Catching
- poj 2385 Apple Catching
- POJ 2385 Apple Catching
- poj 2385 Apple Catching
- POJ 2385 Apple Catching
- Apple Catching.(POJ-2385)
- poj 2385 Apple Catching
- poj 2385 Apple Catching
- POJ 2385Apple Catching
- poj 2385 Apple Catching
- POJ 2385 Apple Catching
- POJ 2385 Apple Catching
- POJ 2385 Apple Catching
- POJ 2385 Apple Catching
- POJ 2385 Apple Catching
- poj-2385-Apple Catching
- Apple Catching POJ 2385
- PL/SQL (三)
- 设计模式-命令模式
- <C/C++图>搜索算法:DFS与BFS
- 【剑指offer】【旋转数组的最小数字 】二分查找的变体
- ios开发 解析Json数组
- poj Apple Catching
- hadoop集群启动顺序
- sxt7.15
- switch、break、continue
- android的jni访问linux原生so
- 数据处理神器Pandas的相关函数
- threejs制作3d模型展示网页
- 《java 多线程编程核心技术》读书笔记一
- “玲珑杯”ACM比赛 Round #18 B -- 数论你还会快速幂【规律】