結果
問題 | No.943 取り調べ |
ユーザー |
![]() |
提出日時 | 2019-12-06 01:46:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 49 ms / 1,206 ms |
コード長 | 1,239 bytes |
コンパイル時間 | 1,898 ms |
コンパイル使用メモリ | 171,936 KB |
実行使用メモリ | 7,296 KB |
最終ジャッジ日時 | 2024-12-23 04:44:31 |
合計ジャッジ時間 | 3,080 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define int long long#define REP(i,n) for(int i = 0;i < (int)(n);i++)#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)#define FOR(i,s,n) for(int i = s;i < (int)n;i++)#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)#define ALL(a) a.begin(),a.end()#define IN(a, x, b) (a<=x && x<b)template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}constexpr long long INF = 1e18;#define endl '\n'#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)int dp[1ll << 18];signed main(){IOS();int N;cin >> N;vector<vector<int>>x(N,vector<int>(N));REP(i,N)REP(j,N)cin>>x[i][j];vector<int>a(N);REP(i,N)cin>>a[i];vector<int>sum(1ll << N);REP(i,1ll<<N){int t = 0;REP(j,N){if(i & (1ll << j))t += a[j];}sum[i] = t;}vector<int>bit(N);REP(i,N){REP(j,N){if(x[i][j])bit[i] |= 1ll << j;}}REP(i,1ll<<N)dp[i] = INF;REP(i,1ll<<N){CHMIN(dp[i],sum[i]);REP(j,N){if(i&(1ll<<j))continue;if((bit[j]&i)==bit[j])CHMIN(dp[i^(1ll<<j)],dp[i]);}}cout<<dp[(1ll<<N)-1]<<endl;/*REP(i,1ll<<N){cout<<i<<" "<<dp[i]<<endl;}*/}