結果

問題 No.90 品物の並び替え
ユーザー DialBirdDialBird
提出日時 2017-03-08 11:35:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 828 bytes
コンパイル時間 1,898 ms
コンパイル使用メモリ 146,608 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 23:28:16
合計ジャッジ時間 2,495 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 4 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 5 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 27 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,first,last) for (int i=first;i<last;++i)
#define MAX(x,y) (x > y ? x : y)
#define MIN(x,y) (x < y ? x : y)

int N, M;
int scores[10][10];
vector<int> nums;
vector<int> made;
vector<int> fl(9, 0);
int ans = 0;

void solve(int cnt){
  if (cnt >= N) {
    int sum = 0;
    REP(i,0,N-1){
      REP(j,i+1,N){
        sum += scores[made[i]][made[j]];
      }
    }
    ans = MAX(sum, ans);
    return;
  }

  REP(i,0,N){
    if (fl[i] != 1) {
      fl[i] = 1;
      made.push_back(nums[i]);
      solve(cnt + 1);
      made.pop_back();
      fl[i] = 0;
    }
  }
}

int main(){
  cin >> N >> M;

  REP(i,0,N){
    nums.push_back(i);
  }

  int it_1, it_2, s;
  REP(i,0,M){
    cin >> it_1 >> it_2 >> s;
    scores[it_1][it_2] = s;
  }

  solve(0);
  cout << ans << endl;
}
0