結果
| 問題 |
No.357 品物の並び替え (Middle)
|
| コンテスト | |
| ユーザー |
FF256grhy
|
| 提出日時 | 2016-04-02 03:10:17 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 5,000 ms |
| コード長 | 697 bytes |
| コンパイル時間 | 148 ms |
| コンパイル使用メモリ | 23,552 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-02 09:22:33 |
| 合計ジャッジ時間 | 817 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:7:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
7 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:10:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | scanf("%d%d%d", &a, &b, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
int score[14][14], dp[1 << 14], queue[1 << 14], get = 0, set = 0;
int main() {
int n, m, i, j;
scanf("%d%d", &n, &m);
for(i = 0; i < m; i++) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
score[a][b] = c;
}
dp[0] = 1;
//queue[0] = 0;
set++;
while(get != set) {
for(i = 0; i < n; i++) {
if( ( queue[get] & (1 << i) ) == 0 ) {
int next = queue[get] + (1 << i);
int s = dp[ queue[get] ];
for(j = 0; j < n; j++) {
if( queue[get] & (1 << j) ) { s += score[j][i]; }
}
if(dp[next] == 0) { queue[set] = next; set++; }
dp[next] = dp[next] < s ? s : dp[next];
}
}
get++;
}
printf("%d\n", dp[(1 << n) - 1] - 1);
return 0;
}
FF256grhy