Submission #58288


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <bits/stdc++.h>
// #include <iostream>
// #include <fstream>
// #include <string>
// #include <map>
// #include <vector>
// #include <algorithm>
// #include <regex>
// #include <chrono>
// #include <sstream>
// #include <iomanip>
// #include <queue>
// #include <stack>
// #include <set>
// #include <unordered_map>
// #include <unordered_set>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long
struct IoSetup {
IoSetup() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cerr << fixed << setprecision(10);
}
}IoSetup;
typedef long long ll;
typedef pair < int , int > pii;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 998244353;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};
bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T&b){if(a<b)return(a=b,1);return 0;}
template<class T>bool chmin(T &a, const T&b){if(b<a)return(a=b,1);return 0;}
int n;
int a[22][22];
ll dp[1<<22];
signed main() {
cin >> n;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
memset(dp, 0x3f, sizeof(dp));
dp[0] = 0;
for(int s = 0; s < (1<<n); s++) {
int i = __builtin_popcount(s);
for(int j = 0; j < n; j++) {
if(!(s&(1<<j))) {
chmin(dp[s|(1<<j)], dp[s] + a[j][i]);
}
}
}
cout << dp[(1<<n)-1] << endl;
return 0;
}

ステータス

項目 データ
問題 1108 - 発表会
ユーザー名 ei1821
投稿日時 2020-01-28 16:17:49
言語 C++14
状態 Accepted
得点 1
ソースコード長 1765 Byte
最大実行時間 113 ms
最大メモリ使用量 33464 KB

セット

セット 得点 Cases
1 ALL 1 / 1 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
case01.in AC 113 ms 33372 KB
1
case02.in AC 94 ms 33452 KB
1
case03.in AC 96 ms 33276 KB
1
case04.in AC 93 ms 33356 KB
1
case05.in AC 90 ms 33308 KB
1
case06.in AC 95 ms 33268 KB
1
case07.in AC 90 ms 33348 KB
1
case08.in AC 96 ms 33428 KB
1
case09.in AC 92 ms 33376 KB
1
case10.in AC 90 ms 33332 KB
1
case11.in AC 92 ms 33412 KB
1
case12.in AC 97 ms 33240 KB
1
case13.in AC 99 ms 33320 KB
1
case14.in AC 92 ms 33272 KB
1
case15.in AC 89 ms 33352 KB
1
case16.in AC 98 ms 33304 KB
1
case17.in AC 91 ms 33384 KB
1
case18.in AC 94 ms 33464 KB
1
case19.in AC 89 ms 33288 KB
1
case20.in AC 97 ms 33364 KB
1
sample01.in AC 22 ms 33188 KB
1
sample02.in AC 27 ms 33272 KB
1