結果

問題 No.519 アイドルユニット
ユーザー koprickykopricky
提出日時 2017-07-16 22:46:51
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,564 bytes
コンパイル時間 1,387 ms
コンパイル使用メモリ 163,592 KB
実行使用メモリ 79,360 KB
最終ジャッジ日時 2024-04-16 22:38:47
合計ジャッジ時間 5,732 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:56:48: warning: ‘id’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   56 |             int next = st + (1 << emp[0]) + (1 << id);
      |                                             ~~~^~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout <<" "<<kbrni;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 24;

int dp[1 << MAX_N];
int fav[MAX_N][MAX_N];

int main()
{
    int n;
    cin >> n;
    rep(i,n){
        rep(j,n){
            cin >> fav[i][j];
        }
    }
    for(int i=0;i<=n-2;i+=2){
        vector<bool> v(n);
        fill(v.end() - i, v.end(), true);
        do {
            vector<int> emp;
            int st = 0;
            rep(i,n) {
                if (v[i]) {
                    st += (1 << i);
                }else{
                    emp.pb(i);
                }
            }
            int mx = 0;
            int id;
            rep(j,emp.size()-1){
                if(mx < fav[emp[0]][emp[j+1]]){
                    mx = fav[emp[0]][emp[j+1]];
                    id = emp[j+1];
                }
            }
            int next = st + (1 << emp[0]) + (1 << id);
            dp[next] = max(dp[next],dp[st]+mx);
        } while (next_permutation(v.begin(), v.end()));
    }
    cout << dp[(1 << n) - 1] << endl;
    return 0;
}
0