結果

提出番号 1767
提出者 phyllo
言語 C++
提出日時 2018-08-04 13:48:35
問題名 (70)アルゴリズムのお勉強
結果 AC
点数 100%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 AC 100% 2ms 8720KB
2 AC 100% 2ms 7824KB
3 AC 100% 2ms 8432KB
4 AC 100% 3ms 7776KB
5 AC 100% 2ms 7792KB
6 AC 100% 2ms 8672KB
7 AC 100% 2ms 8000KB
8 AC 100% 2ms 7616KB
9 AC 100% 2ms 8128KB
10 AC 100% 2ms 8416KB
11 AC 100% 2ms 7776KB
12 AC 100% 2ms 7232KB
13 AC 100% 2ms 7776KB
14 AC 100% 2ms 8112KB
15 AC 100% 2ms 8144KB
16 AC 100% 2ms 8720KB
17 AC 100% 2ms 8480KB
18 AC 100% 2ms 7632KB
19 AC 100% 2ms 7248KB
20 AC 100% 2ms 8656KB
21 AC 100% 2ms 8656KB
22 AC 100% 2ms 8688KB
23 AC 100% 2ms 8416KB
24 AC 100% 4ms 8416KB
25 AC 100% 2ms 8720KB
26 AC 100% 3ms 8256KB
27 AC 100% 4ms 7792KB
28 AC 100% 2ms 8432KB
29 AC 100% 12ms 8688KB
30 AC 100% 3ms 7808KB

ソースコード

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const int INF = (int)1e9;

int dp[(1<<16) + 10];
int T[20];
int A[20][20];

int main(){
  int N;
  cin >> N;
  rep(i,N){
    cin >> T[i];
  }
  rep(i,N){
    rep(j,N){
      cin >> A[i][j];
    }
  }

  rep(i,(1<<16)+10) dp[i] = INF;
  dp[0] = 0;
  
  for(int S=0; S<(1<<N); S++){
    rep(i,N){
      if(((S>>i)&1) == 0){
        int t = T[i];
        rep(j,N){
          if((S>>j)&1){
            t -= A[j][i];
          }
        }
        dp[S | (1<<i)] = min(dp[S | (1<<i)], dp[S] + t);
      }
    }
  }

  cout << dp[(1<<N)-1] << endl;
  
  return 0;
}