結果

提出番号 1822
提出者 rickytheta
言語 C++
提出日時 2018-08-04 14:06:11
問題名 (70)アルゴリズムのお勉強
結果 AC
点数 100%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 AC 100% 2ms 7632KB
2 AC 100% 2ms 8416KB
3 AC 100% 2ms 8112KB
4 AC 100% 2ms 8416KB
5 AC 100% 2ms 7520KB
6 AC 100% 2ms 7248KB
7 AC 100% 2ms 8416KB
8 AC 100% 2ms 7968KB
9 AC 100% 1ms 8640KB
10 AC 100% 2ms 7792KB
11 AC 100% 2ms 8416KB
12 AC 100% 2ms 7632KB
13 AC 100% 2ms 8112KB
14 AC 100% 2ms 7984KB
15 AC 100% 2ms 8000KB
16 AC 100% 2ms 7984KB
17 AC 100% 2ms 7520KB
18 AC 100% 2ms 8736KB
19 AC 100% 2ms 8016KB
20 AC 100% 2ms 8416KB
21 AC 100% 2ms 8016KB
22 AC 100% 3ms 8400KB
23 AC 100% 2ms 7824KB
24 AC 100% 4ms 7824KB
25 AC 100% 2ms 7536KB
26 AC 100% 3ms 8432KB
27 AC 100% 4ms 8096KB
28 AC 100% 2ms 8128KB
29 AC 100% 12ms 7728KB
30 AC 100% 3ms 7824KB

ソースコード

#include <bits/stdc++.h>

using namespace std;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int dp[1<<16];

int n;
int t[25];
int a[25][21];

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%d",t+i);
  REP(i,n)REP(j,n)scanf("%d",&a[i][j]);
  REP(i,1<<n)dp[i] = 1<<30;
  dp[0] = 0;
  REP(m,(1<<n)-1){
    REP(i,n)if((~m>>i)&1){
      int tm = t[i];
      REP(j,n)if((m>>j)&1)tm -= a[j][i];
      CHMIN(dp[m | (1<<i)], dp[m] + tm);
    }
  }
  printf("%d\n",dp[(1<<n)-1]);
  return 0;
}