結果

提出番号 2425
提出者 Focus_Sash
言語 C++
提出日時 2021-04-27 19:00:54
問題名 (70)アルゴリズムのお勉強
結果 CE
点数 0%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 CE 0% 0ms 0KB
2 CE 0% 0ms 0KB
3 CE 0% 0ms 0KB
4 CE 0% 0ms 0KB
5 CE 0% 0ms 0KB
6 CE 0% 0ms 0KB
7 CE 0% 0ms 0KB
8 CE 0% 0ms 0KB
9 CE 0% 0ms 0KB
10 CE 0% 0ms 0KB
11 CE 0% 0ms 0KB
12 CE 0% 0ms 0KB
13 CE 0% 0ms 0KB
14 CE 0% 0ms 0KB
15 CE 0% 0ms 0KB
16 CE 0% 0ms 0KB
17 CE 0% 0ms 0KB
18 CE 0% 0ms 0KB
19 CE 0% 0ms 0KB
20 CE 0% 0ms 0KB
21 CE 0% 0ms 0KB
22 CE 0% 0ms 0KB
23 CE 0% 0ms 0KB
24 CE 0% 0ms 0KB
25 CE 0% 0ms 0KB
26 CE 0% 0ms 0KB
27 CE 0% 0ms 0KB
28 CE 0% 0ms 0KB
29 CE 0% 0ms 0KB
30 CE 0% 0ms 0KB

ソースコード

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> pl;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vl, greater<>> pqr;
struct edge {
    ll from;
    ll to;
    ll cost;
    edge(ll f, ll t, ll c) : from(f), to(t), cost(c) { }
};
typedef vector<vector<ll> > Graph;
typedef vector<vector<edge> > WGraph;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep3(i, k, n) for(int i = k; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define pb emplace_back
#define V vector
#define SZ(x) (x).size()
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#define uniquify(vec) (vec).erase(std::unique((vec).begin(), (vec).end()), (vec).end())
constexpr ll MOD1 = 1e9 + 7;
constexpr ll MOD9 =  998244353;
constexpr ll INF = MOD1*MOD1+1;

ll dnum(ll d){
    return to_string(d).length();
}

ll power(ll x, ll n){
    ll ret=1;
    while(n>0){
        if(n&1) ret = ret * x;
        x = x*x;
        n >>= 1;
    }
    return ret;
}

template<typename T>
void rsort(V<T> &v){
    sort(all(v), greater<T>());
}

template<typename T, typename S>
std::ostream &operator<<(std::ostream& os, const pair<T, S> &p){
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
std::ostream &operator<<(std::ostream& os, const vector<T> &v){
    int n = v.size();
    os << "[";
    for(int i = 0; i < n; i++){
        if(i == n - 1) os << v[i];
        else os << v[i] << ", ";
    }
    os << "]";
    return os;
}



template <typename T, typename S>
std::ostream &operator<<(std::ostream& os, const map<T, S> &mp){
    for(auto iter = mp.begin(); iter != mp.end(); iter++){
        os << "(" << iter->first << ", " << iter->second << ")" << " ";
    }
    return os;
}

template <typename T>
std::ostream &operator<<(std::ostream& os, const set<T> &s){
    os << "{";
    for(auto c : s) os << c << " ";
    os << "}";
    return os;
}

template <typename T>
bool chmax(T &a, const T& b) {
    if (a < b) {a = b; return true;}
    return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
    if (a > b) {a = b; return true;}
    return false;
}

template <typename T>
void fin(const T &a){
    cout << a << '\n';
    exit(0);
}



int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    ll n; cin >> n;
    vl t(n); rep(i,n) cin >> t[i];
    V<vl> a(n, vl(n));
    rep(i,n) rep(j,n) cin >> a[i][j];

    vl dp(1<<n, INF);
    dp[0] = 0;
    rep(S, 1<<n){
        rep(i, n){
            if(S & (1<<i)) continue;
            ll red = 0;
            rep(j,n){
                if(S & (1<<j)) red += a[j][i];
            }
            chmin(dp[S|(1<<i)], dp[S] + t[i] - red);
        }
    }
    cout << dp[(1<<n)-1] << '\n';

    return 0;
}