結果

問題 No.90 品物の並び替え
ユーザー koba-e964koba-e964
提出日時 2015-06-07 16:03:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 905 bytes
コンパイル時間 453 ms
コンパイル使用メモリ 68,764 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 19:38:06
合計ジャッジ時間 1,101 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;

const int N = 9;
int dp[1 << N];
int mat[N][N];

int main(void){
  int n, m;
  cin >> n >> m;
  REP (i, 0, m) {
    int i1, i2, s;
    cin >> i1 >> i2 >> s;
    mat[i1][i2] = s;
  }
  REP(bits, 0, 1 << n) {
    int ma = 0;
    REP(i, 0, n) {
      if ((bits & (1 << i)) == 0) {
	continue;
      }
      int gain = 0;
      REP (j, 0, n) {
	if ((bits & (1 << j)) == 0) {
	  continue;
	}
	gain += mat[j][i];
      }
      ma = max(dp[bits ^ (1 << i)] + gain, ma);
    }
    dp[bits] = ma;
  }
  cout << dp[(1 << n) - 1] << endl;
}
0