結果
問題 |
No.519 アイドルユニット
|
ユーザー |
![]() |
提出日時 | 2017-06-18 20:20:24 |
言語 | C90 (gcc 12.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 812 bytes |
コンパイル時間 | 459 ms |
コンパイル使用メモリ | 22,656 KB |
実行使用メモリ | 80,660 KB |
最終ジャッジ日時 | 2024-10-01 20:30:31 |
合計ジャッジ時間 | 4,924 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | TLE * 1 -- * 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)); | ^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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; }