結果

問題 No.90 品物の並び替え
コンテスト
ユーザー horiesiniti
提出日時 2016-07-20 10:53:04
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 707 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 396 ms
コンパイル使用メモリ 74,368 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2026-05-05 06:35:49
合計ジャッジ時間 1,186 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;
int sc[10][10];
int ans=0;
int n;

void f(int no,int bs,int score){
	if(bs==((1<<n)-1)){
		ans=std::max(ans,score);
	}else{
		for(int i=0;i<n;i++){
			int b=(1<<i);
			if((bs&b)==0){
				int sum=0;
				for(int j=0;j<n;j++){
					int b2=(1<<j);
					if((bs&b2)!=0){
						sum+=sc[j][i];
					}
				}
				f(i,bs|b,score+sum);
			}
		}
	}
}

int main() {
	// your code goes here
	int m;
	scanf("%d %d",&n,&m);
	memset(sc,0,sizeof(sc));
	for(int i=0;i<m;i++){
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		sc[a][b]=c;
	}
	for(int i=0;i<n;i++){
		int b=(1<<i);
		f(i,b,0);
	}
	std::cout<<ans<<"\n";
	return 0;
}
0