結果

問題 No.90 品物の並び替え
ユーザー IL_mstaIL_msta
提出日時 2015-06-15 21:20:03
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,305 bytes
コンパイル時間 1,154 ms
コンパイル使用メモリ 77,120 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-21 02:18:26
合計ジャッジ時間 1,689 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>

#include <algorithm>
#include <cmath>

#include <string>
#include <list>
#include <queue>
#include <vector>
#include <complex>

/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) std::cout<<(p)<<std::endl;
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
int rg[9][9];
int dp[1024][9];

int solve(int num,int cost,int Max,int prev){
	if(num == (1<<Max)-1){
		return cost;
	}
	/*if(prev != -1 && dp[num][prev] != -1){
		return dp[num][prev];
	}*/

	int ans = -1;
	int temp = 0;
	for(int i=0;i<Max;++i){
		if( (num & (1<<i)) ==0){
			if(prev==-1){
				temp = solve( num | (1<<i), cost, Max,i);
			}else{
				temp = solve( num | (1<<i), cost + rg[prev][i], Max,i);
			}

			if(ans == -1 || ans < temp){
				ans = temp;
			}
		}
	}
	/*if(prev != -1){
		dp[num][prev] = ans;
	}*/
	return ans;
}
int main(void){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    //cout << setprecision(6);//
	
	int N,M;
	cin>>N>>M;
	
	int a,b,c;
	rep(i,N)rep(j,N)rg[i][j]=0;
	rep(i,M){
		cin>>a>>b>>c;
		rg[a][b] = c;
	}
	
	//dp[1024][9]
	rep(i,1024)rep(k,9)dp[i][k]=-1;
	int ans = solve(0,0,N,-1);
	P(ans);
	return 0;
}
0