poj 3661 Running】的更多相关文章

Description The cows are trying to become better athletes, so Bessie ≤ N ≤ ,) minutes. During each minute, she can choose to either run or rest for the whole minute. The ultimate distance Bessie runs, though, depends on her . When she chooses to run…
题意:给你一个n,m,n表示有n分钟,每i分钟对应的是第i分钟能跑的距离,m代表最大疲劳度,每跑一分钟疲劳度+1,当疲劳度==m,必须休息,在任意时刻都可以选择休息,如果选择休息,那么必须休息到疲劳度为0,当然,当疲劳度为0的时候也是可以继续选择休息的,求在n分钟后疲劳度为0所跑的最大距离 思路:dp[i][j]表示在第i分钟疲劳度为j的时候所跑的最大距离,dp[i][j]=dp[i-1][j-1]+d[i]:这个转移,说的是,第i分钟选择跑步,当然,第i分钟可以选择不跑步,那么就是选择休息,题…
题意:Bessie要运动N分钟,已知每一分钟可以跑的距离,每一分钟可选择跑或者不跑,若选择跑,疲劳度加1,但疲劳度不能超过M:若选择不跑,则每过一分钟,疲劳度减1,且只有当疲劳度减为0时可以继续跑.求运动N分钟后且疲劳度恰好为0时可以跑的最远距离. 分析: 1.dp[i][j]---第i分钟疲劳度为j时可以跑的最远距离. 2.dp[i][0] = dp[i - 1][0]---在第i分钟选择休息. 3.dp[i][0] = Max(dp[i][0], dp[i - j][j])---在第i-j分…
Running Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5652   Accepted: 2128 Description The cows are trying to become better athletes, so Bessie is running on a track for exactly N (1 ≤ N ≤ 10,000) minutes. During each minute, she can…
题目链接: http://poj.org/problem?id=3661 题目大意:牛跑步.有N分钟,M疲劳值.每分钟跑的距离不同.每分钟可以选择跑步或是休息.一旦休息了必须休息到疲劳值为0.0疲劳值也可以花费1分钟去休息.最后疲劳值必须为0,问跑的最大距离. 解题思路: 怎么看都像个随便YY的DP. 用dp[i][j]表示第i分钟,疲劳值为j的最大距离. 首先考虑第i分钟休息问题: ①上次已经疲劳为0,这次又休息.dp[i][0]=dp[i-1][0]. ②上次疲劳为k.dp[i][0]=ma…
2015-07-16 问题简述: 动态求取中位数的问题,输入一串数字,每输入第奇数个数时求取这些数的中位数. 原题链接:http://poj.org/problem?id=3784 解题思路: 求取中位数的方法常常想到使用堆来实现:取一个大顶堆,一个小顶堆,使大顶堆的堆顶记录中位数,因此,要时刻保持大顶堆堆顶元素小于小顶堆堆顶元素,且大顶堆元素个数等于小顶堆元素个数或等于小顶堆元素个数加一. 以下有两种堆得实现方法: 一:直接使用STL中的函数(make_heap,push_heap,pop_h…
Description For this problem, you will write a program that reads in a sequence of 32-bit signed integers. After each odd-indexed value is read, output the median (middle value) of the elements received so far. Input The first line of input contains…
题目链接:http://poj.org/problem?id=3784 题目大意:依次输入n个数,每当输入奇数个数的时候,求出当前序列的中位数(排好序的中位数). 此题可用各种方法求解. 排序二叉树方法,每个结点保存以其为根的左右子树中数的个数.如果数据出的够严格,这种方法会被卡的,除非是通过动态调整维持树的高度较小. 排序二叉树的代码如下: #include <cstdio> using namespace std; #define N 20000 struct Node { int v;…
Description For this problem, you will write a program that reads in a sequence of 32-bit signed integers. After each odd-indexed value is read, output the median (middle value) of the elements received so far. Input The first line of input contains…
题意: 思路: i表示到了i,j表示疲劳度为j f[i][j]表示能跑的最大距离 f[i][j]=f[i-1][j-1]+a[i] if(i-j>=0)f[i][0]=max(f[i][0],f[i-j][j]); f[i][0]=max(f[i][0],f[i-1][0]); //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using namespace std;…