当前位置:网站首页>Class homework (5) -- 576. Hungry cattle
Class homework (5) -- 576. Hungry cattle
2022-07-23 15:55:00 【xyc20120615】
Catalog
Description
The cattle line up in front of the feed trough . The feed trough is used in turn 1 To N(1≤N≤2000) Number . Every night , A lucky cow according to John's rules , Eat some of the feed in the trough .
John offers B A list of intervals . An interval is a pair of integers start−end(1≤start≤end≤N), It means some continuous feed tanks , such as 1-3,7-8,3-4 wait . Cattle can choose any range , But the range chosen by cattle cannot overlap .
Of course , Cattle hope they can eat as much as possible . Give some intervals , Help the cow find some ranges , Make it eat the most .
In the example above ,1-3 and 3-4 It's overlapping ; Smart cattle choose {1-3,7-8}, So you can eat 5 Something in a slot .
Format
Input
The first 1 That's ok , Integers B(1≤B≤1000).
The first 2∼B+1 That's ok , Two integers per line , Represents an interval , The smaller endpoint is in front .
Output
Only one integer , It indicates the maximum number of food in the trough .
Samples
input data 1
3
1 3
7 8
3 4
Output data 1
5
Limitation
1s, 1024KiB for each test case
Answer key :
Be similar to Arrangement of the lecture hall , The idea is similar , That is to open a structure and change it into 0/1 knapsack , When looping, pay attention to the subscript 0 To traverse the .
State transition equation :
dp[j]=max(dp[j],dp[a[i].s-1]+a[i].h);// State transition equation Program :
#include <bits/stdc++.h>
using namespace std;
int n,dp[2010];
struct H{
int s,e,h;//s Is the subscript of the first trough of the interval ,e Is the subscript of the last trough of the interval ,h Is the number of slots in the interval
}a[2010];
bool cmp(H x,H y){// Sorting criteria
return x.e<y.e;
}
int main(){
cin>>n;
for(int i=0;i<n;i++){// Input the subscript of the first trough of the interval and the subscript of the last trough of the interval, and calculate the number of trough of the interval
cin>>a[i].s>>a[i].e;
a[i].h=a[i].e-a[i].s+1;
}
sort(a,a+n,cmp);// Sort
for(int i=0;i<n;i++){// Traverse each trough section
for(int j=a[n-1].e;j>=a[i].e;j--)
dp[j]=max(dp[j],dp[a[i].s-1]+a[i].h);// State transition equation
}
cout<<dp[a[n-1].e];
return 0;
}边栏推荐
- C# 关闭当前电脑指令
- Six ways of uniapp route jump
- Vim到底可以配置得多漂亮?
- [7.16] code source - [array division] [disassembly] [select 2] [maximum common divisor]
- On 'premature optimization'
- 超详细MP4格式分析
- VMware virtual machine download, installation and use tutorial
- 【Try to Hack】sql注入 Less7 (into outfile和布尔盲注)
- select......for update 语句的功能是什么? 会锁表还是锁行?
- [attack and defense world web] difficulty Samsung 9 points introductory question (Part 1): simple_ js、mfw
猜你喜欢

软件测试周刊(第81期):能够对抗消极的不是积极,而是专注;能够对抗焦虑的不是安慰,而是具体。

後綴錶達式(暑假每日一題 4)

C语言经典例题-将输入的两位数转成英文

没有了华为,高通任意涨价,缺乏核心技术的国产手机只能任由宰割

Batch deletion with RPM -e --nodeps

Vim到底可以配置得多漂亮?

Mercedes Benz new energy product line: luxury new energy market may change the pattern

2022最NB的JVM基础到调优笔记,吃透阿里P6小case

Quickly master QML Chapter 5 components
![[attack and defense world web] difficulty Samsung 9 points introductory question (Part 2): shrink, lottery](/img/05/06dd9f071fe18e4a50d767ec51e557.png)
[attack and defense world web] difficulty Samsung 9 points introductory question (Part 2): shrink, lottery
随机推荐
C语言经典例题-商品检验码
md5强碰撞,二次解码,
C语言注释的方法
Fileinputformat of MapReduce inputformat
day1
【攻防世界WEB】难度三星9分入门题(中):ics-05、easytornado
Clickhouse, let the query fly!!!
Learning summary of ugly code
[pyGame practice] playing poker? Win or lose? This card game makes me forget to eat and sleep.
Can multithreading optimize program performance?
Learning about patents
3D math - vector
备份内容哈哈哈
奔驰新能源产品线:豪华新能源市场或将改变格局
select......for update 语句的功能是什么? 会锁表还是锁行?
Go: Gin urlencoded format
Remember SQL optimization once
Safe and reasonable use of electricity to harvest a cool "summer"
第一篇 项目基本情况介绍
第三篇 RBAC权限管理 数据库设计详解