POJ-2385-Apple Catching
来源:互联网 发布:c语言函数 chm 编辑:程序博客网 时间:2024/05/13 18:24
题目大意是说有2棵苹果树,你可以选择站在其中的一棵树下,然后每秒在两棵树中的一棵可能有苹果落下,你每秒可以选择移动到另外一棵树或者不移动。只有当你在树下的时候才能接到苹果。现在题目给你共有k次移动的机会,然后问你最多可以得到多少个苹果。
其实算是比较简单的动态规划,转移方程式: dp[i][j][k]=max(dp[i-1][j][k]+1,dp[i-1][j^1][k-1]+1)(i表示第几秒,j表示哪棵树,k表示用了多少次移动。 如果当前树不为落下苹果的,那么删去+1
代码:
#include<cstdio>#include<cstring>#include<iostream>using namespace std;const int maxn=1100;int t,w,a[maxn],dp[maxn][2][31];int main(){ while(scanf("%d%d",&t,&w)!=EOF) {for(int i=0;i<t;i++){ scanf("%d",&a[i]); a[i]--;}for(int i=0;i<t;i++) for(int k=0;k<=w;k++) {if(k==0){ dp[i][a[i]][k]=dp[i-1][a[i]][k]+1; dp[i][a[i]^1][k]=dp[i-1][a[i]^1][k]; continue;}dp[i][a[i]][k]=max(dp[i-1][a[i]][k]+1,dp[i-1][a[i]^1][k-1]+1);dp[i][a[i]^1][k]=max(dp[i-1][a[i]^1][k],dp[i-1][a[i]][k-1]); }int ans=0;for(int i=0;i<=w;i++) ans=max(ans,max(dp[t-1][0][i],dp[t-1][1][i]));printf("%d\n",ans); } 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
- poj 1007
- perl的几个小知识点
- English in The World
- Oracle安装(2)通过SHELL脚本快速安装Oracle11gR2软件
- 30岁之前创业四次:最大痛苦是知道自己错了
- POJ-2385-Apple Catching
- spring常用jar包详解
- wxFormBuilder怎么制作继承于wxWindow的窗口,便于集成在frame中
- 奇偶页不同页眉页脚设置
- 网络字节序与主机字节序
- JBPM (五) Task通过EL表达式和AssignHandler监听分配任务
- Objective-C中的Json解析,NSUTF8Encoding,
- hadoop(1)
- 包装类概念(面向对象高级)