結果
| 問題 |
No.90 品物の並び替え
|
| コンテスト | |
| ユーザー |
IL_msta
|
| 提出日時 | 2015-06-15 21:20:03 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,305 bytes |
| コンパイル時間 | 719 ms |
| コンパイル使用メモリ | 82,860 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-06 21:03:13 |
| 合計ジャッジ時間 | 1,570 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | WA * 9 |
ソースコード
#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;
}
IL_msta