【动态规划】[luoguP1868]饥饿的奶牛
来源:互联网 发布:淘宝宝贝下载软件 编辑:程序博客网 时间:2024/06/05 20:37
题目
一开始又没用读懂题
DP题 dp[i]表示牛走到i这个位置能吃到的最大草数 最后ans找最大值
关键找最右的端点 然后从0一直找过去(为什么从0找我也不知道 一开始从1找wa了一个大点 从0找就ac了)
代码如下
#include<iostream>#include<cstdio>#include<cctype>#include<algorithm> using namespace std; #define in = read(); typedef long long ll; typedef unsigned int ui; const ll size = 5000000 + 10000; struct data{ ll x , y;}a[size]; int n; ll rightpoint , j = 1 , ans; ll f[size];inline ll read(){ ll num = 0 , f = 1; char ch = getchar(); while(!isdigit(ch)){ if(ch == '-') f = -1; ch = getchar(); } while(isdigit(ch)){ num = num*10 + ch - '0'; ch = getchar(); } return num*f;}inline bool cmp(data a , data b){ return a.x != b.x ? a.x < b.x : a.y < b.y;}int main(){ n in; for(register int i=1;i<=n;i++){ a[i].x in; a[i].y in; rightpoint = max(rightpoint , a[i].y); } sort(a + 1 , a + n + 1 , cmp); for(register int i=0;i<=rightpoint;i++){ f[i] = max(f[i] , f[i - 1]); while(a[j].x == i && j <= n){ f[a[j].y] = max(f[a[j].y] , f[a[j].x - 1] + a[j].y - a[j].x + 1); j ++; } ans = max(ans , f[i]); } printf("%lld" , ans);}//COYG
阅读全文
0 0
- 【动态规划】[luoguP1868]饥饿的奶牛
- 动态规划 洛谷P1868 饥饿的奶牛
- BZOJ 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛|动态规划
- P1868 饥饿的奶牛
- 饥饿的奶牛
- P1868 饥饿的奶牛
- |Tyvj|动态规划|1023 奶牛的锻炼
- P1868 饥饿的奶牛(区间问题)
- bzoj1669 [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- [BZOJ1669][Usaco2006 Oct]Hungry Cows饥饿的奶牛
- BZOJ1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- BZOJ1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- bzoj 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛 暴力
- bzoj 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- BZOJ1669 [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- bzoj1669 [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- 【USACO2.3.2】奶牛家谱 动态规划
- BaaS、FaaS、Serverless都是什么馅儿?
- Last packet sent to the server was 0 ms ago服务器报错
- leetcode_194. Transpose File ? 待解决
- Google Pixel 2夺得DxOMark排名第一,是否说明双摄并没什么用?
- idea破解方式
- 【动态规划】[luoguP1868]饥饿的奶牛
- mongodb官方练习数据库
- 历史上最全的正则表达式
- iOS nslog 使用 十六进制输出
- Ubuntu 11.10中如何解决:Gtk-WARNING ___ 无法在模块路径中找到主题引擎:“pixmap”问题
- WebScoket消息推送
- AWS S3 三个常用的客户端软件使用方式Cloudberry, CyberDuck, S3Fox
- 蹲草丛--dfs或者bfs找最小的连着草丛i
- decode()的用法