結果
| 問題 |
No.357 品物の並び替え (Middle)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-06 10:35:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 945 bytes |
| コンパイル時間 | 436 ms |
| コンパイル使用メモリ | 57,868 KB |
| 最終ジャッジ日時 | 2025-01-07 01:25:08 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 WA * 17 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:45:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
45 | scanf("%d %d", &N, &M);
| ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:47:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
47 | scanf("%d %d %d", &item1[i], &item2[i], &score[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX_N = 14, MAX_M = MAX_N * (MAX_N - 1);
struct edge { int to, cost; };
vector<edge> G[MAX_N];
void add_edge(int from, int to, int cost) {
G[from].push_back(edge{ to, cost });
}
int N, M;
int item1[MAX_M], item2[MAX_M], score[MAX_M];
int dp[1 << MAX_N];
void solve() {
for (int i = 0; i < M; i++) {
add_edge(item1[i], item2[i], score[i]);
}
sizeof(dp, -1, sizeof(dp));
for (int S = 0; S < (1 << N); S++) {
for (int i = 0; i < N; i++) {
if (S >> i & 1) {
for (int e = 0; e < G[i].size(); e++) {
edge j = G[i][e];
if (!(S >> j.to & 1)) {
dp[S | 1 << j.to] = max(dp[S | 1 << j.to], dp[S] + j.cost);
}
}
}
}
}
printf("%d\n", dp[(1 << N) - 1]);
}
int main() {
scanf("%d %d", &N, &M);
for (int i = 0; i < M; i++) {
scanf("%d %d %d", &item1[i], &item2[i], &score[i]);
}
solve();
}