結果

問題 No.519 アイドルユニット
ユーザー 👑 horiesinitihoriesiniti
提出日時 2016-06-25 09:58:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 113 ms / 1,000 ms
コード長 948 bytes
コンパイル時間 413 ms
コンパイル使用メモリ 48,368 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 06:09:49
合計ジャッジ時間 2,715 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
6,816 KB
testcase_01 AC 112 ms
6,940 KB
testcase_02 AC 38 ms
6,940 KB
testcase_03 AC 5 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 5 ms
6,940 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 6 ms
6,940 KB
testcase_14 AC 6 ms
6,940 KB
testcase_15 AC 5 ms
6,940 KB
testcase_16 AC 6 ms
6,940 KB
testcase_17 AC 6 ms
6,940 KB
testcase_18 AC 6 ms
6,940 KB
testcase_19 AC 5 ms
6,940 KB
testcase_20 AC 6 ms
6,940 KB
testcase_21 AC 5 ms
6,940 KB
testcase_22 AC 6 ms
6,944 KB
testcase_23 AC 5 ms
6,944 KB
testcase_24 AC 14 ms
6,940 KB
testcase_25 AC 14 ms
6,940 KB
testcase_26 AC 14 ms
6,944 KB
testcase_27 AC 14 ms
6,944 KB
testcase_28 AC 15 ms
6,940 KB
testcase_29 AC 108 ms
6,940 KB
testcase_30 AC 113 ms
6,940 KB
testcase_31 AC 112 ms
6,944 KB
testcase_32 AC 111 ms
6,940 KB
testcase_33 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         scanf("%d",&n);
      |         ~~~~~^~~~~~~~~
main.cpp:13:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |                         scanf("%d",&e);
      |                         ~~~~~^~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#include<map>
const int LIMIT=30;
int main(){
	//このコードを模範解答としてください。
	int n,e;
	int as[LIMIT][LIMIT];
	
	std::map<int,int> dp[LIMIT+1];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			scanf("%d",&e);
			as[i][j]=e;
		}
	}
	dp[0][0]=0;
	
	for(int i=0;i<n;i+=2){
		std::map<int,int>::iterator it;
		for(it=dp[i].begin();it!=dp[i].end();it++){
			int perm=(*it).first;
			int score=(*it).second;
			for(int k=0;k<n;k++){
				int add1=(1<<k);
				if((perm&add1)!=0){
					continue;
				}
				
				for(int l=k+1;l<n;l++){
					if(k==l)continue;
					int add2=(add1|(1<<l));
					if((perm&add2)!=0)continue;
					int perm2=(perm|add2);
					int score2=score+as[k][l];
					if(dp[i+2].find(perm2)==dp[i+2].end()){
						dp[i+2][perm2]=score2;
					}else if(dp[i+2][perm2]<score2){
						dp[i+2][perm2]=score2;
					}
				}
				break;
			}
		}
		
	}
	printf("%d\n",dp[n][(1<<n)-1]);
}
0