poj2385 - Apple Catching【动态规划】】的更多相关文章

                                            $Apple~Catching$ Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16248   Accepted: 8009 $Description$ It is a little known fact that cows love apples. Farmer John has two apple trees (which are…
题目传送门 Apple Catching Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15444   Accepted: 7582 Description It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 an…
Description It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, each full of apples. Bessie cannot reach the apples when they are on the tree, so she must wait for t…
https://vjudge.net/problem/POJ-2385 猛刷简单dp的第一天的第一题. 状态:dp[i][j]表示第i秒移动j次所得的最大苹果数.关键要想到移动j次,根据j的奇偶判断人在哪里. 想了挺久的,最后还是参考了一篇和自己思路最近的代码https://blog.csdn.net/hellohelloc/article/details/52050207 我比他缺少的是特判dp[i][0]的状态,后面的一切都以此为基础的. #include<iostream> #inclu…
思路: 简单dp. 实现: #include <iostream> #include <cstdio> #include <cstring> using namespace std; ]; ][][]; int dfs(int now,int cur,int rem) { ) return dp[now][cur][rem]; if(now == t) ; ,cur,rem) + (cur == x[now] - ); ) p = max(p, dfs(now, - c…
Apple Catching 直接翻译了 Descriptions 有两棵APP树,编号为1,2.每一秒,这两棵APP树中的其中一棵会掉一个APP.每一秒,你可以选择在当前APP树下接APP,或者迅速移动到另外一棵APP树下接APP(移动时间可以忽略不计),但由于却乏锻炼,你最多移动W次.问在T秒内,你最多能收集多少个APP.假设你开始站在1号APP树下. Input 第1行:两个整数T(1 < = T< = 1000)和W(1 < = W< = 30)第2..T+1行:1或2,代…
Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9978   Accepted: 4839 Description It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, eac…
Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9831   Accepted: 4779 Description It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, eac…
dp dp( x , k ) = max( dp( x - 1 , k - 1 ) + *** , dp( x - 1 , k ) + *** ) *** = 0 or 1 ,根据情况 (BZOJ 1750双倍经验) ------------------------------------------------------------------------ #include<cstdio> #include<cstring> #include<algorithm>…
3384/1750: [Usaco2004 Nov]Apple Catching 接苹果 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 18  Solved: 16[Submit][Status][Discuss] Description     很少有人知道奶牛爱吃苹果.农夫约翰的农场上有两棵苹果树(编号为1和2),每一棵树上都长满了苹果.奶牛贝茜无法摘下树上的苹果,所以她只能等待苹果从树上落下.但是,由于苹果掉到地上会摔烂,贝茜必须在半空中接住…
Apple Catching   Description It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, each full of apples. Bessie cannot reach the apples when they are on the tree, so sh…
Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13447   Accepted: 6549 Description It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, ea…
双倍经验题... -->1750 dp!! 3384: [Usaco2004 Nov]Apple Catching 接苹果 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 61  Solved: 52[Submit][Status][Discuss] Description     很少有人知道奶牛爱吃苹果.农夫约翰的农场上有两棵苹果树(编号为1和2),每一棵树上都长满了苹果.奶牛贝茜无法摘下树上的苹果,所以她只能等待苹果从树上落下.但是,由于苹果掉…
bzoj3384[Usaco2004 Nov]Apple Catching 接苹果 bzoj1750[Usaco2005 qua]Apple Catching 题意: 两棵树,每分钟会从其中一棵树上掉一个苹果下来,捡苹果的人只愿意W次,问初始在树1处最多能捡多少苹果.分钟数≤1000,W≤30. 题解: dp.f[i][j][0/1]表示第i分钟移动了j次现在在第2/1棵树下.具体看代码. 代码: #include <cstdio> #include <cstring> #incl…
终于开始写dp了,还很不熟练 It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, each full of apples. Bessie cannot reach the apples when they are on the tree, so she must wait fo…
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cstdlib> using namespace std; int T, W; //T 时间内 , W : 来回的次数 + ; ]; /* dp[i][j]: 给定时刻i, 转移次数已知为 j :即上一时刻同一棵树 或 上一时刻 不同的树 :则这一时刻在转移次数为j的情况下…
传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 有两颗苹果树,在每一时刻只有其中一棵苹果树会掉苹果,而Bessie可以在很短的时间内在两个苹果树间切换,但每一时刻只能切换一下: 求在1~T时刻,Bessie在最多可以切换W次的前提下最多可以获得多少苹果? 题解: 定义变量dp[ i ][ j ] : 前 i 时刻,移动 j 步所获得的最大的苹果数量: 据此写出状态转移方程: 如何判断在i处是否的到苹果呢? ①如果dp[i-1…
Description It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, each full of apples. Bessie cannot reach the apples when they are on the tree, so she must wait for t…
Description It and ) in his field, each full of apples. Bessie cannot reach the apples when they are on the tree, so she must wait for them to fall. However, she must catch them in the air since the apples bruise when they hit the ground (and no one…
题意:2棵苹果树在T分钟内每分钟随机由某一棵苹果树掉下一个苹果,奶牛站在树#1下等着吃苹果,它最多愿意移动W次,问它最多能吃到几个苹果.思路:不妨按时间来思考,一给定时刻i,转移次数已知为j, 则它只能由两个状态转移而来.即上一时刻同一棵树或上一时刻不同的树    dp[i][j] = max(dp[i-1][j], dp[i-1][j-1]);则这一时刻在转移次数为j的情况下最多能接到的苹果为那两个状态的最大值再加上当前能接受到的苹果.(注意当前能否拿到苹果只与转移次数有关)    if (j…
It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, each full of apples. Bessie cannot reach the apples when they are on the tree, so she must wait for them to fall.…
牛如何吃苹果 问题大意:一个叫Bessie的牛,可以吃苹果,然后有两棵树,树上苹果每分钟会掉一个,这只牛一分钟可以在两棵树中往返吃苹果(且不吃地上的),然后折返只能是有限次W,问你这只叫Bessie的牛最多可以吃到多少个苹果 首先我们应该很容易想到,这个必须要用DP去做,然后就是考虑怎么储存旧值的问题了,因为树有两棵,然后每个往返状态对应不同的结果,所以我们应该用一个二维矩阵去储存(苹果的个数就不重要了,因为我们只用算到最后,前面的都可以扔掉). 然后状态方程应该怎么写呢?也很简单,定义一个状态…
比起之前一直在刷的背包题,这道题可以算是最纯粹的dp了,写下简单题解. 题意是说cows在1树和2树下来回移动取苹果,有移动次数限制,问最后能拿到的最多苹果数,含有最优子结构性质,大致的状态转移也不难想出,以 dp[i][j] 表示第 i 分钟使用了 j 次移动机会时能获得的最多苹果数(不需3维,因为 j 隐含着在1树还是2树的信息,判奇偶性即可,一开始 0min 时在1树),大体的状态转移方程就是: dp[i][j] = j & 1 ? c[i][2] : c[i][1] + max ( dp…
一道DP题, f[i,j,k] 表示 第 k 时刻 由 1 位置 变换 j 次 到达 当前 i 棵树 注意也要维护 变换 0 次的情况. var i,j,k,t,w,now:longint; tree:array[..,..] of longint; f:array[..,..,..] of longint; function max(a,b:longint):longint; begin if a>b then exit(a) else exit(b); end; begin readln(t…
01背包的基础上增加一个维度表示当前在的树的哪一边. #include<cstdio> #include<iostream> #include<string> #include<cstring> #include<queue> #include<vector> #include<stack> #include<vector> #include<map> #include<set> #in…
题意 : 有两颗苹果树,在 1~T 的时间内会有两颗中的其中一颗落下一颗苹果,一头奶牛想要获取最多的苹果,但是它能够在树间转移的次数为 W 且奶牛一开始是在第一颗树下,请编程算出最多的奶牛获得的苹果数 分析 : 这题是不可能爆搜的,可组合的情况实在太多....... 定义 dp[ i ][ j ] ==> 在第 i 个时间点下已经转移了 j 次的最多苹果数是多少 根据定义和奶牛一开始在一号树这个条件,所以初始化时有两种情况 如果第一个时间点落下苹果的是一号树则初始化 dp[ 1 ][ 0 ] =…
Description 有两棵APP树,编号为1,2.每一秒,这两棵APP树中的其中一棵会掉一个APP.每一秒,你可以选择在当前APP树下接APP,或者迅速移动到另外一棵APP树下接APP(移动时间可以忽略不计),但由于却乏锻炼,你最多移动W次.问在T秒内,你最多能收集多少个APP.假设你开始站在1号APP树下. Input 第1行:两个整数T(1 < = T< = 1000)和W(1 < = W< = 30)第2..T+1行:1或2,代表每分钟掉落APP的那棵树的编号 Outpu…
题意:有两棵树,标号为1和2,在Tmin内,每分钟都会有一个苹果从其中一棵树上落下,问最多移动M次的情况下(该人可瞬间移动),最多能吃到多少苹果.假设该人一开始在标号为1的树下. 分析: 1.dp[x][y][z]---第x分钟移动了y次的情况下,现在位于标号为z的树下最多吃到的苹果数. 2.枚举所有的时间.次数和可能位于的树下. 若第i分钟该人位于标号为k的树下,第i + 1分钟苹果从标号为a[i+1]的树上落下. (1)k==a[i], 此人站在标号为k的树下不移动,即可再吃到一个苹果:dp…
POJ3176 Cow Bowling 题意 输入一个n层的三角形,第i层有i个数,求从第1层到第n层的所有路线中,权值之和最大的路线. 规定:第i层的某个数只能连线走到第i+1层中与它位置相邻的两个数中的一个. 思路 最显而易见的是使用二维数组动态规划计算. 比如dp[i][j]表示以第i行j列的位置作为终点的路线的最大权值. (注意区分初始化时的意义) 那么dp[i][j]的最大值取决于dp[i-1][j-1]和dp[i-1][j],从这两者之间筛选出最大值,加到dp[i][j]上,即为dp…
图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Journey poj1724 - ROADS(邻接表+DFS) BFS poj3278 - Catch That Cow(空间BFS) poj2251 - Dungeon Master(空间BFS) poj3414 - Pots poj1915 - Knight Moves poj3126 - Prim…