結果

問題 No.90 品物の並び替え
ユーザー startcppstartcpp
提出日時 2014-12-07 19:51:48
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 988 bytes
コンパイル時間 1,217 ms
コンパイル使用メモリ 77,048 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-02 09:31:59
合計ジャッジ時間 1,461 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
using namespace std;

int n,m;
int item1[9],item2[9], score[9];
vector<int> per;	//i番目にある品物の番号を格納
int ban[9];			//品物iが何番目にあるのかをban[i]に格納

int main(){
	int i,j;
	int ans = 0;
	
	cin >> n >> m;
	
	for( i = 0; i < m; i++ )
		cin >> item1[i] >> item2[i] >> score[i];
	
	for( i = 0; i < n; i++ )
		per.push_back(i);
	
	do{
		for( i = 0; i < n; i++ ){
			for( j = 0; j < n; j++ ){
				if( i == per[j] )
					break;
			}
			ban[i] = j;
		}
		
		int x = 0;
		for( i = 0; i < m; i++ ){
			if( ban[ item1[i] ] < ban[ item2[i] ] )
				x += score[i];
		}
		ans = max( x, ans );
	}while( next_permutation( per.begin(), per.end() ) );
	cout << ans << endl;
	return 0;
}
0