結果

問題 No.357 品物の並び替え (Middle)
ユーザー zuvizudarzuvizudar
提出日時 2017-12-05 20:09:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,525 bytes
コンパイル時間 828 ms
コンパイル使用メモリ 98,232 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-19 03:33:48
合計ジャッジ時間 1,710 ms
ジャッジサーバーID
(参考情報)
judge15 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PP(p) cout<<(p)<<" ";
#define pb push_back
#define mp make_pair
#define INF 1e18

typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef pair<int, int> pi;
//int dy[8]={1,1,1,0,-1,-1,-1,0};
//int dx[8]={-1,0,1,1,1,0,-1,-1};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

int N,M;
vi dp;
vvi d;
void input(){
	cin>>N>>M;
	dp.resize(1<<N,-1);
	d.resize(N+1,vi(N+1,0));
	rep(i,M){
		int a,b,c;
		cin>>a>>b>>c;
		d[a][b]=c;
	}
}
int d2b(int n){
	vi b(32,0);
	int i;
	for(i=0;n>0;i++){
		b[i]=n%2;
		n/=2;
	}
	while(i>0)PP(b[--i]);
	return 0;
}
int dfs(int S){
	if(S>=(1<<N)-1){
		return 0;
	}
	if(dp[S]!=-1)return dp[S];
	int ret=0;
	rep(i,N){
		if((S>>i)&1)continue;
		int tmp=dfs(S|1<<i);
		rep(j,N){
			if((S>>j)&1)continue;
			tmp+=d[i][j];
		}
		ret=max(ret,tmp);
	}
	return dp[S]=ret;
}
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	input();
	int ans=0;
	vi t;
	P(dfs(0))
	return 0;
}

0