結果
| 問題 |
No.90 品物の並び替え
|
| コンテスト | |
| ユーザー |
nenuon
|
| 提出日時 | 2017-03-01 22:28:32 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 16 ms / 5,000 ms |
| コード長 | 1,404 bytes |
| コンパイル時間 | 625 ms |
| コンパイル使用メモリ | 83,148 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-12 22:47:02 |
| 合計ジャッジ時間 | 1,161 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define ll long long
#define PI acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
//方針
//Nが小さいので順列を全探索しても9!=362880パターン=4*10^5くらい
//得られる点数は2重ループで計算する0(M*M/2)
//ギリギリ?
int main(){
int N, M;
cin >> N >> M;
//点数を保存score[後][前]
int score[N][N];
//memset(score, 0, sizeof(score));
FOR(i, 0, N) FOR(j, 0, N) score[i][j] = 0;
FOR(i, 0, M){
int item1, item2, tmpscore;
cin >> item1 >> item2 >> tmpscore;
score[item2][item1] = tmpscore;
}
//全探索0~N-1の並び替え
vector<int> v;
FOR(i, 0, N) v.push_back(i);
int ans = 0;
do{
int ret = 0;
//v[usiro]が後ろにある数字v[mae]が前にある数字
//なのでそれをscoreの配列に入れて点数を調べる
FOR(usiro, 1, N){
FOR(mae, 0, usiro){
ret += score[v[usiro]][v[mae]];
}
}
ans = max(ans, ret);
}while(next_permutation(v.begin(), v.end()));
cout << ans << endl;
}
nenuon