当前位置:网站首页>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;
}
边栏推荐
- Spark SQL UDF function
- Graph theory and concept
- Spark SQL common time functions
- Binary complement
- Idea eye care settings
- How to finally generate a file from saveastextfile in spark
- Run redis on docker to start in the form of configuration file, and the connection client reports an error: server closed the connection
- JVM parameter configuration details
- Phased summary of the research and development of the "library management system -" borrowing and returning "module
- Yan required executor memory is above the max threshold (8192mb) of this cluster!
猜你喜欢

为什么PrepareStatement性能更好更安全?

Node learning

Distributed principle - what is a distributed system

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

ML - natural language processing - Basics

How to solve the login problem after the 30 day experience period of visual stuido2019

分布式原理 - 什么是分布式系统

Phased summary of the research and development of the "library management system -" borrowing and returning "module

Idea护眼色设置

使用cpolar建立一个商业网站(如何购买域名)
随机推荐
带你创建你的第一个C#程序(建议收藏)
Idea remotely submits spark tasks to the yarn cluster
GAMES101复习:三维变换
Spark partition operators partitionby, coalesce, repartition
ZOJ - 4114 Flipping Game-dp,合理状态表示
wait()和sleep()的区别理解
Deadlock gossip
PAT甲级题目目录
Take you to learn more about JS basic grammar (recommended Collection)
IOS interview questions
PAT甲级1152 Google Recruitment (20 分)
Seata中jdbc下只有一个lib嘛?
ML - natural language processing - Key Technologies
Submarine cable detector tss350 (I)
Redis elimination strategy list
matlab randint,Matlab的randint函数用法「建议收藏」
Image cropper example
matlab 如何保存所有运行后的数据
Implementation of asynchronous FIFO
C language function review (pass value and address [binary search], recursion [factorial, Hanoi Tower, etc.))