当前位置:网站首页>2021 Shanghai match-b-ranked DP
2021 Shanghai match-b-ranked DP
2022-07-25 15:33:00 【Brother Tazi is here】
The main idea of the topic :
Here you are. n n n A triad ( a i , b i , c i ) (a_i,b_i,c_i) (ai,bi,ci). Each dimension should be selected separately a , b , c ( a + b + c = n ) a,b,c(a+b+c=n) a,b,c(a+b+c=n) One makes the most value .
Topic ideas :
Start with greed :
In the case of two tuples , We just need to be right b − a b-a b−a Choose greedily after sorting b individual b i b_i bi The remaining choices a i a_i ai.
After digging out a subsequence of the sorted sequence, it still conforms to the nature of greed . Therefore, we can analyze the third dimension d p ( i , j ) dp(i,j) dp(i,j) On behalf of i A triad , Yes j j j individual c i c_i ci Maximum value of .
Ruodi i i i No choice , According to the nature , When i ≤ b i \leq b i≤b Greedy choice b b b, Reverse selection a a a.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vll vector<ll>
#define fi first
#define se second
const int maxn = 5000 + 5;
const int mod = 1e9 + 7;
struct Node{
int a , b , c;
bool operator < (const Node & g){
return b - a > g.b - g.a;
}
}a[maxn];
ll dp[maxn][maxn];
int main()
{
ios::sync_with_stdio(false);
int n , x , y , z; cin >> n >> x >> y >> z;
for (int i = 1 ; i <= n ; i++){
cin >> a[i].a >> a[i].b >> a[i].c;
}
sort(a + 1 , a + 1 + n);
for (int i = 0 ; i <= n ; i++)
for (int j = 0 ; j <= n ; j++)
dp[i][j] = -1e18;
dp[0][0] = 0;
for (int i = 1 ; i <= n ; i++){
for (int j = 0 ; j <= i ; j++){
if (j)
dp[i][j] = dp[i - 1][j - 1] + a[i].c;
int rest = i - j;
if (rest <= y) dp[i][j] = max(dp[i][j] , dp[i - 1][j] + a[i].b);
else dp[i][j] = max(dp[i][j] , dp[i - 1][j] + a[i].a);
}
}
cout << dp[n][z] << endl;
return 0;
}
边栏推荐
- 带你创建你的第一个C#程序(建议收藏)
- IOS interview questions
- 死锁杂谈
- Image cropper example
- Qtime定义(手工废物利用简单好看)
- 获取键盘按下的键位对应ask码
- MySQL installation and configuration super detailed tutorial and simple database and table building method
- Xcode添加mobileprovision证书文件报错:Xcode encountered an error
- Pytorch学习笔记--常用函数总结3
- Remember that spark foreachpartition once led to oom
猜你喜欢

BPSK调制系统MATLAB仿真实现(1)

Spark partition operators partitionby, coalesce, repartition

小波变换--dwt2 与wavedec2

GAMES101复习:变换

Spark memory management mechanism new version

No tracked branch configured for branch xxx or the branch doesn‘t exist. To make your branch trac

matlab 优化工具 manopt 安装

Understanding the difference between wait() and sleep()

wait()和sleep()的区别理解

Implementation of asynchronous FIFO
随机推荐
matlab 优化工具 manopt 安装
The difference between Apple buy in and apple pay
ML - 语音 - 高级语音模型
C#精挑整理知识要点9 集合2(建议收藏)
2021上海市赛-H-二分答案
带你详细认识JS基础语法(建议收藏)
2021上海市赛-D-卡特兰数变种,dp
Spark AQE
C # carefully sorting out key points of knowledge 11 entrustment and events (recommended Collection)
异步fifo的实现
How spark gets columns in dataframe --column, $, column, apply
How to update JSON values in the database?
自定义注解校验API参数电话号
HBCK fix problem
MySQL优化总结二
Local cache --ehcache
How to solve the problem of scanf compilation error in Visual Studio
C language function review (pass value and address [binary search], recursion [factorial, Hanoi Tower, etc.))
ML - 图像 - 深度学习和卷积神经网络
使用cpolar建立一个商业网站(如何购买域名)