【DP】POJ 2385
来源:互联网 发布:文华模拟交易软件 编辑:程序博客网 时间:2024/06/06 01:59
题意:又是Bessie 这头牛在折腾,这回他喜欢吃苹果,于是在两棵苹果树下等着接苹果,但苹果不能落地后再接,吃的时间不算,假设他能拿得下所有苹果,但是这头牛太懒了【POJ另一道题目说它是头勤奋的奶牛,我也不知道说什么好了】,他只愿意移动W次,问你在T时间内能拿到的最多的苹果是多少?
想法:根据题目解释,最开始在第一棵或者第二棵树都没关系,就看你要不要移动一次,状态转移方程是dp[i][j] = max(dp[i-1][j-1],dp[i-1][j]),其中i代表时间,其中j是代表来回的次数,如果是偶次,那就在第一棵树下,奇次,就在第二棵树下面,apples[i][j],其中j就是存的在第一棵树还是第二棵树。不过这题POJ数据貌似很水。
/**测试数据:7 221122116**/#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 1100;int apples[MAXN][2];int dp[MAXN+10][MAXN+10];int main(){int W,T;while(~scanf("%d%d",&T,&W)){ memset(dp,0,sizeof(dp)); int ans =0,a = 0;for(int i=1;i<=T;i++){ int location;scanf("%d",&location);apples[i][location-1] = 1;}for(int i=1;i<=T;i++){ dp[i][0] = dp[i-1][0]+apples[i][0]; //注意处理这里 for(int j=1;j<=W;j++){ dp[i][j] = max(dp[i-1][j],dp[i-1][j-1])+apples[i][j%2];}}for(int i=0;i<=W;i++)ans = max(ans,dp[T][i]);printf("%d\n",ans);}return 0;}
0 0
- poj 2385 简单dp
- Poj 2385 (dp)
- DP 之 poj 2385
- POJ-2385(DP)
- 【DP】POJ 2385
- poj 2385 经典dp
- POJ 2385 DP
- 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]
- 获取分辨率 尺寸、样式
- 居中大全
- VC2010用IE调试OCX单步
- Java class对象的详解
- poj-3061-Subsequence 尺取法/双指针法
- 【DP】POJ 2385
- postgresql数据库存储图片文件
- you need to use a Theme.AppCompat theme(or descenbant) with this activity
- java多线程-专题-聊聊并发(十)生产者消费者模式
- 关于st的插件,我之前windows用的插件有哪些?
- UITableView修改Cell的宽度问题
- Android使用http协议的GET和POST方法!!!
- struts2配置文件Demo_Me
- javascript中的数组的使用