POJ 2385 Apple Catching
来源:互联网 发布:淘宝开店培训骗局 编辑:程序博客网 时间:2024/05/17 06:14
题目链接:http://poj.org/problem?id=2385
大体题意是有两棵苹果树,每分钟都有一个苹果从任意一棵树上掉下来,有人能在树下接住苹果,但只能接住一棵树下的;但来回两棵树之间的次数是有限的,求在有限的次数下,能得到的最多的苹果的数量。
这也是题DP,动态规划。dp[i][j]表示在i分钟之内变换j次位置能得到的最大数量,则递推关系式为:
dp[i][j]=max(dp[i-1][j],dp[i-1][j])
如果此时人刚好站在这棵树下,dp[i][j]++;
dp[i][0]还需要单独考虑,代码如下:
#include <iostream>#include <cstdio>using namespace std;int num[1111];int dp[1111][40];int max(int a,int b){ return a>b?a:b;}int main(){ int T,w; scanf("%d%d",&T,&w); for(int i=1;i<=T;i++) scanf("%d",&num[i]); dp[1][0]=1; dp[1][1]=1; for(int i=1;i<=T;i++) for(int j=0;j<i&&j<=w;j++) { if(j==0) { dp[i][j]=dp[i-1][j]+num[i]%2; continue; } dp[i][j]=max(dp[i-1][j],dp[i-1][j-1]); if(j%2+1==num[i]) dp[i][j]++; } printf("%d\n",dp[T][w]); 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
- android SQLite
- 简单LED驱动创建和使用
- eclipse插件m2eclipse(maven)安装出现maven integration for eclipse JDK warnings
- Andriod Handler更新UI
- 电路中各种地的接地处理
- POJ 2385 Apple Catching
- PL/SQL 工具的设置
- 浙江大学 ZOJ ACM 1002 FireNet 题解
- java垃圾回收浅析
- HandleEvent
- Remove Duplicates from Sorted Array
- Android Native开发(一)JNI
- Android颜色代码
- 随机产生一个限定范围的long型数字