POJ 2385 Apple Catching (DP)
来源:互联网 发布:沐足软件 编辑:程序博客网 时间:2024/05/22 06:59
传送门:POJ 2385
题意:一共两棵苹果树,每分钟两棵苹果树的其中一颗会掉落一个苹果,你可以在两棵树之间移动,每次只能接到一棵果树下的苹果,移动时间忽略不计,在T时间内最多只能移动W次,求最多能接到的苹果数。
题解:dp[i][j][k]代表第i分钟移动了j次在第k个树下接到的最多的苹果数。
(很遗憾这道题是参考别人的代码做出来的= =)
#include <iostream>using namespace std;int main(){ int i,j,t,w,maxn; int data[1002],dp[1002][40][2]; while(cin>>t>>w) { for(i=1;i<=t;i++) cin>>data[i]; for(i=1,maxn=-1;i<=t;i++) { dp[i][0][0]=dp[i-1][0][0]+(data[i]==1); dp[i][0][1]=dp[i-1][0][1]+(data[i]==2);//起始点赋初值 for(j=1;j<=w;j++) { dp[i][j][0]=max(dp[i-1][j][0],dp[i-1][j-1][1])+(data[i]==1); dp[i][j][1]=max(dp[i-1][j][1],dp[i-1][j-1][0])+(data[i]==2);//判断此时所在的树是否掉落,掉落加1,反之加0 maxn=max(maxn,max(dp[i][j][0],dp[i][j][1]));//取此时在tree1下和tree2下的最大值 } } cout<<maxn<<endl; } return 0;}
0 0
- POJ 2385 Apple Catching (DP)
- POJ 2385 Apple Catching (dp)
- Apple Catching (poj 2385 简单dp)
- poj--2385--Apple Catching(状态dp)
- POJ 2385 Apple Catching(DP)
- POJ 2385 Apple Catching(基础DP)
- POJ - 2385 Apple Catching (DP)
- POJ 2385 Apple Catching(线性DP)
- POJ 2385 Apple Catching(DP)
- POJ 2385 Apple Catching DP
- POJ 2385 Apple Catching [DP]
- POJ 2385 Apple Catching DP
- poj 2385 Apple Catching DP
- POJ 2385 Apple Catching (DP)
- POJ 2385 Apple Catching DP
- poj 2385 Apple Catching DP
- poj 2385 Apple Catching dp
- poj 2385 Apple Catching DP
- memcpy和memmove的区别与联系
- POJ 2395
- Linux I/O Performance Tests using dd
- Java类加载机制
- sicily 1935. 二叉树重建
- POJ 2385 Apple Catching (DP)
- 中断处理(中断向量寄存器)
- DatePicker的使用(三):初始化
- U3D-隐性的局部变量
- 深入理解计算机系统 - 引言
- mac os x 10.8 安装python-mysqldb
- winsock API积累
- Monkeyrunner学习一
- 观察者模式-气象台的实现与应用