求条
  • 板块P1392 取数
  • 楼主xrz114514
  • 当前回复1
  • 已保存回复1
  • 发布时间2025/7/23 17:43
  • 上次更新2025/7/23 22:40:51
查看原帖
求条
1307139
xrz114514楼主2025/7/23 17:43
#include <bits/stdc++.h>

using namespace std;

const int N = 8e2 + 1;

int n, m, k, a[N][N];
vector<int> v;

struct P{
  int x, y, sum;
};

struct cmp{
  bool operator ()(const P &i, const P &j) const{
    return i.sum > j.sum;
  }
};

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m >> k;
  v.push_back(0);
  for(int i = 1; i <= n; ++i){
    priority_queue<P, vector<P>, cmp> tmp;
    vector<int> res;
    for(int j = 1; j <= m; ++j){
      cin >> a[i][j];
      tmp.push({j, 0, a[i][j] + v[0]});
    }
    sort(a[i], a[i] + m + 1);
    for(int i = 1; i <= k; ++i){
      int x = tmp.top().x, y = tmp.top().y + 1;
      res.push_back(tmp.top().sum);
      tmp.pop();
      if(y < v.size()){
        tmp.push({x, y, a[i][x] + v[y]});
      }
    }
    v = res;
    sort(v.begin(), v.end());
  }
  for(int i : v){
    cout << i << ' ';
  }
  return 0;
}

2025/7/23 17:43
加载中...