結果

問題 No.90 品物の並び替え
ユーザー 👑 horiesinitihoriesiniti
提出日時 2016-07-20 10:53:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 707 bytes
コンパイル時間 494 ms
コンパイル使用メモリ 56,920 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 16:59:20
合計ジャッジ時間 875 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 4 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 31 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 |         scanf("%d %d",&n,&m);
      |         ~~~~~^~~~~~~~~~~~~~~
main.cpp:38:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |                 scanf("%d %d %d",&a,&b,&c);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;
int sc[10][10];
int ans=0;
int n;

void f(int no,int bs,int score){
	if(bs==((1<<n)-1)){
		ans=std::max(ans,score);
	}else{
		for(int i=0;i<n;i++){
			int b=(1<<i);
			if((bs&b)==0){
				int sum=0;
				for(int j=0;j<n;j++){
					int b2=(1<<j);
					if((bs&b2)!=0){
						sum+=sc[j][i];
					}
				}
				f(i,bs|b,score+sum);
			}
		}
	}
}

int main() {
	// your code goes here
	int m;
	scanf("%d %d",&n,&m);
	memset(sc,0,sizeof(sc));
	for(int i=0;i<m;i++){
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		sc[a][b]=c;
	}
	for(int i=0;i<n;i++){
		int b=(1<<i);
		f(i,b,0);
	}
	std::cout<<ans<<"\n";
	return 0;
}
0