結果
| 問題 | No.357 品物の並び替え (Middle) | 
| コンテスト | |
| ユーザー |  dnish | 
| 提出日時 | 2017-03-26 14:14:56 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 6 ms / 5,000 ms | 
| コード長 | 560 bytes | 
| コンパイル時間 | 1,280 ms | 
| コンパイル使用メモリ | 167,640 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-06 06:27:40 | 
| 合計ジャッジ時間 | 1,856 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 18 | 
ソースコード
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<(S)<<endl
#define ck(a,b) (0<=(a)&&(a)<b)
using namespace std;
int dp[1<<14];
int main(){
	int n,m;
	cin>>n>>m;
	int score[14][14];
	int a,b;
	REP(i,0,n) REP(j,0,n) score[i][j]=0;
	REP(i,0,m) {
		cin>>a>>b;
		cin>>score[a][b];
	}
	REP(i,0,1<<n) dp[i]=0;
	REP(mask,0,1<<n){
		REP(j,0,n){
			if((mask & 1<<j) ==0){
				int cost=0;
				REP(i,0,n) if((mask & 1<<i)) cost+=score[i][j];
				dp[mask|1<<j]=max(dp[mask|1<<j],dp[mask]+cost);
			}
		}
	}
	p(dp[(1<<n)-1]);
	return 0;
}
            
            
            
        