結果

問題 No.519 アイドルユニット
ユーザー akakimidoriakakimidori
提出日時 2017-06-18 20:20:24
言語 C90
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 812 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 22,912 KB
実行使用メモリ 80,768 KB
最終ジャッジ日時 2024-04-09 20:15:00
合計ジャッジ時間 4,826 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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.c: In function ‘run’:
main.c:27:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |   scanf("%d",&n);
      |   ^~~~~~~~~~~~~~
main.c:33:7: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |       scanf("%d",f+POS(i,j));
      |       ^~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>

#define POS(i,j) ((i)*n+(j))
#define MAX(a,b) ((a)>(b)?(a):(b))

int calc(int bit,int n,int *f,int *dp){
  if(dp[bit]!=-1) return dp[bit];

  int res=0;
  int i,j;
  for(i=0;i<n;i++){
    if((bit>>i)&0x01){
      for(j=i+1;j<n;j++){
	if((bit>>j)&0x01){
	  res=MAX(res,f[POS(i,j)]+calc(bit^(1<<i)^(1<<j),n,f,dp));
	}
      }
    }
  }
  dp[bit]=res;
  return res;
}

void run(void){
  int n;
  scanf("%d",&n);

  int *f=(int *)malloc(sizeof(int)*n*n);
  int i,j;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",f+POS(i,j));
    }
  }

  int *dp=(int *)malloc(sizeof(int)*(1<<n));
  for(i=0;i<(1<<n);i++){
    dp[i]=-1;
  }
  dp[0]=0;
  int ans=calc((1<<n)-1,n,f,dp);
  printf("%d\n",ans);
  free(f);
  free(dp);
  return;
}

int main(void){
  run();
  return 0;
}
0