专栏文章
P12247 跳舞机 题解
P12247题解参与者 1已保存评论 0
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mipk85t3
- 此快照首次捕获于
- 2025/12/03 13:21 3 个月前
- 此快照最后确认于
- 2025/12/03 13:21 3 个月前
45 pts
不难想到 dp。
定义状态 表示,前 分钟兴奋值之和的最大值。
转移时枚举玩家 ,转移方程为:
直接转移的复杂度为 (视 同阶),期望得分 。
100 pts
考虑如何优化转移,容易想到使用优先队列。
先将玩家按 升序排列。
每次转移前,将当前满足条件的玩家出队,并将不满足条件的玩家出队,之后选择当前队首,即 最大的玩家,进行转移即可。
复杂度 。
CPP#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 5e5 + 10;
struct Node{
int l, r, w;
}a[MAXN];
bool cmp(Node x, Node y){
return x.l < y.l;
}
int dp[MAXN];
priority_queue <pair<int, int>> q;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
for (int i = 1;i <= n;i++) cin >> a[i].l >> a[i].r >> a[i].w;
sort(a + 1, a + n + 1, cmp);
int cur = 1;
for (int i = 1;i <= m;i++){
dp[i] = dp[i - 1];
while (cur <= n && a[cur].l <= i - k + 1){
if (a[cur].r >= i) q.push({a[cur].w, a[cur].r});
cur++;
}
while (!q.empty() && q.top().second < i) q.pop();
if (i >= k && !q.empty()) dp[i] = max(dp[i], dp[i - k] + q.top().first);
}
cout << dp[m] << endl;
return 0;
}
相关推荐
评论
共 0 条评论,欢迎与作者交流。
正在加载评论...