結果
| 問題 |
No.357 品物の並び替え (Middle)
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2016-04-09 20:06:32 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 5,000 ms |
| コード長 | 1,196 bytes |
| コンパイル時間 | 804 ms |
| コンパイル使用メモリ | 83,996 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-04 05:06:33 |
| 合計ジャッジ時間 | 1,601 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 357.cc: No.357 品物の並び替え (Middle) - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 14;
const int NBITS = 1 << MAX_N;
/* typedef */
/* global variables */
int scs[MAX_N][MAX_N];
int dp[NBITS];
/* subroutines */
/* main */
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int it0, it1, sc;
cin >> it0 >> it1 >> sc;
scs[it0][it1] = sc;
}
memset(dp, -1, sizeof(dp));
dp[0] = 0;
int nbits = 1 << n;
for (int bits = 0; bits < nbits; bits++)
if (dp[bits] >= 0)
for (int i = 0, bi = 1; i < n; i++, bi <<= 1)
if (! (bits & bi)) {
int bitsi = bits | bi;
int sum = dp[bits];
for (int j = 0, bj = 1; j < n; j++, bj <<= 1)
if (bits & bj) sum += scs[j][i];
if (dp[bitsi] < sum) dp[bitsi] = sum;
}
printf("%d\n", dp[nbits - 1]);
return 0;
}
tnakao0123