結果

問題 No.90 品物の並び替え
ユーザー natsugirnatsugir
提出日時 2014-12-07 19:18:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 100 ms / 5,000 ms
コード長 880 bytes
コンパイル時間 1,287 ms
コンパイル使用メモリ 61,432 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-02 09:19:06
合計ジャッジ時間 1,206 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

template<class T> inline T &amin(T &a, T b) { if (a>b) a=b; return a; }
template<class T> inline T &amax(T &a, T b) { if (a<b) a=b; return a; }

int N, M, F[9][9];
int I[9];

int main() {
    scanf("%d%d", &N, &M);
    REP (i, M) {
	int x, y, s;
	scanf("%d%d%d", &x, &y, &s);
	F[x][y] = s;
    }
    REP (i, N) I[i] = i;

    int ans = 0;
    do {
	int sum = 0;
	REP (i, N) {
	    REP (j, N) {
		if (I[i] < I[j]) sum += F[i][j];
	    }
	}
	amax(ans, sum);
    } while (next_permutation(I, I+N));

    printf("%d\n", ans);
    return 0;
}
0