結果

問題 No.616 へんなソート
ユーザー pekempey
提出日時 2017-12-16 06:56:20
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 610 bytes
コンパイル時間 1,018 ms
コンパイル使用メモリ 74,584 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-14 17:25:00
合計ジャッジ時間 6,663 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 TLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const long long mod = 1e9 + 7;

void to(long long &x, long long y) {
  x += y;
  if (x >= mod) x -= mod;
}

int main() {
  int n, K;
  cin >> n >> K;

  vector<long long> dp0(K + 1);
  dp0[0] = 1;

  for (int i = 0; i < n; i++) {
    vector<long long> dp1(K + 1);
    for (int j = 0; j <= K; j++) {
      for (int k = 0; k <= i && j + k <= K; k++) {
        to(dp1[j + k], dp0[j]);
      }
    }
    dp0 = dp1;
  }

  long long ans = 0;
  for (int i = 0; i <= K; i++) {
    (ans += dp0[i]) %= mod;
  }

  cout << ans << endl;
}
0