結果
| 問題 | 
                            No.519 アイドルユニット
                             | 
                    
| コンテスト | |
| ユーザー | 
                             goodbaton
                         | 
                    
| 提出日時 | 2017-05-28 22:56:13 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,316 bytes | 
| コンパイル時間 | 681 ms | 
| コンパイル使用メモリ | 82,532 KB | 
| 実行使用メモリ | 164,388 KB | 
| 最終ジャッジ日時 | 2024-09-21 15:44:16 | 
| 合計ジャッジ時間 | 8,082 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 8 WA * 26 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:62:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   62 |   scanf("%d",&n);
      |   ~~~~~^~~~~~~~~
main.cpp:66:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   66 |       scanf("%d",f[i]+j);
      |       ~~~~~^~~~~~~~~~~~~
            
            ソースコード
#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 visited[1<<24];
int n;
int f[SIZE][SIZE];
vector<int> vec;
void dfs(int h, int key, int last){
  if(h >= n-n/4*2){
    vec.push_back(((1<<n)-1)^key);
    return;
  }
  
  if(visited[key]) return;
  visited[key] = true;
  
  for(int j=last;j<n;j++){
    if((1<<j) & key) continue;
    for(int k=j+1;k<n;k++){
      if((1<<k) & key) continue;
      
      dp[key + (1<<j) + (1<<k)] = max(dp[key + (1<<j) + (1<<k)], dp[key] + f[j][k]);
      dfs(h+2, key + (1<<j) + (1<<k), j+1);
    }
  }
  
}
int main(){
  
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      scanf("%d",f[i]+j);
    }
  }
  dfs(0,0,0);
  int ans = 0;
  
  for(int i=0;i<vec.size();i++){
    int t = vec[i];
    
    ans = max(ans, dp[t] + dp[((1<<n)-1)^(t)]);
  }
   
  printf("%d\n",ans);
  
  return 0;
}
            
            
            
        
            
goodbaton