結果

問題 No.519 アイドルユニット
ユーザー goodbatongoodbaton
提出日時 2017-05-28 22:35:05
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,486 bytes
コンパイル時間 635 ms
コンパイル使用メモリ 82,820 KB
実行使用メモリ 77,576 KB
最終ジャッジ日時 2023-10-21 14:25:10
合計ジャッジ時間 5,171 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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:34:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 |   scanf("%d",&n);
      |   ~~~~~^~~~~~~~~
main.cpp:38:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |       scanf("%d",f[i]+j);
      |       ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 30

int dp[1<<24];

int main(){
  int n;
  int f[SIZE][SIZE];
  scanf("%d",&n);

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      scanf("%d",f[i]+j);
    }
  }

  for(int i=0;i<=n-n/4*2;i+=2){
    int s[26];
    
    for(int j=0;j<n;j++){
      s[n-1-j] = (j < i);
    }
    
    do{
      int t = 0;
      
      for(int j=0;j<n;j++){
        if(s[j]) t += 1 << j;
      }
      
      for(int j=0;j<n;j++){
        if((1<<j) & t) continue;
        for(int k=j+1;k<n;k++){
          if((1<<k) & t) continue;
          
          dp[t + (1<<j) + (1<<k)] = max(dp[t + (1<<j) + (1<<k)], dp[t] + f[j][k]);
          
        }
      }
      
    }while(next_permutation(s,s+n));
    
  }

  int s[26], ans = 0;
  
  for(int i=0;i<n;i++){
    s[n-1-i] = (i < n/4*2);
  }

  do{
    int t = 0;

    for(int i=0;i<n;i++){
      if(s[i]) t += 1 << i;
    }

    ans = max(ans, dp[t] + dp[((1<<n)-1)^(t)]);
    

  }while(next_permutation(s,s+n));
   
  printf("%d\n",dp[(1<<n)-1]);
  
  return 0;
}
0