結果
| 問題 |
No.943 取り調べ
|
| コンテスト | |
| ユーザー |
Rubikun
|
| 提出日時 | 2019-12-05 22:07:47 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 94 ms / 1,206 ms |
| コード長 | 991 bytes |
| コンパイル時間 | 2,026 ms |
| コンパイル使用メモリ | 172,056 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-23 01:15:29 |
| 合計ジャッジ時間 | 3,259 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=100000007,MAX=100005,INF=1<<30;
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int N;cin>>N;
vector<vector<int>> S(N,vector<int>(N));
vector<int> dp((1<<N),INF);
vector<int> A(N);
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
cin>>S[i][j];
}
}
for(int i=0;i<N;i++) cin>>A[i];
dp[0]=0;
for(int bit=0;bit<(1<<N);bit++){
for(int i=0;i<N;i++){
if(bit&(1<<i)) continue;
bool ok=true;
for(int j=0;j<N;j++){
if(S[i][j]&&!(bit&(1<<j))) ok=false;
}
if(ok) dp[bit|(1<<i)]=min(dp[bit|(1<<i)],dp[bit]);
else dp[bit|(1<<i)]=min(dp[bit|(1<<i)],dp[bit]+A[i]);
}
}
cout<<dp[(1<<N)-1]<<endl;
}
Rubikun