結果

問題 No.357 品物の並び替え (Middle)
ユーザー zuvizudarzuvizudar
提出日時 2017-12-05 19:49:47
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,665 bytes
コンパイル時間 925 ms
コンパイル使用メモリ 98,584 KB
実行使用メモリ 5,504 KB
最終ジャッジ日時 2024-05-06 10:40:16
合計ジャッジ時間 1,718 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
vvi dp;
vvi d;
void input(){
	cin>>N>>M;
	dp.resize(1<<N,vi(N+1,-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,int now,vi t){
	if(S>=(1<<N)-1){
	//	rep(i,t.size())PP(t[i])
	//	cout<<endl;
		return 0;
	}
	if(dp[S][now]!=-1)return dp[S][now];
	int ret=0;
	rep(i,N){
		if((S>>i)&1)continue;
		t.pb(i);
		ret=max(ret,dfs(S|1<<i,i,t)+d[now][i]);
		t.pop_back();
	}
	return dp[S][now]=ret;
}
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	input();
	vi t;
	int ans=0;
	rep(i,N){
		//rep(i,(1<<N)-1)dp[i]=-1;
		vi t;
		t.pb(i);
		ans=max(ans,dfs(0|1<<i,i,t));
	}
	P(ans)
	return 0;
}

0