結果
問題 |
No.90 品物の並び替え
|
ユーザー |
![]() |
提出日時 | 2016-07-20 10:53:04 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 35 ms / 5,000 ms |
コード長 | 707 bytes |
コンパイル時間 | 570 ms |
コンパイル使用メモリ | 57,492 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-15 17:30:10 |
合計ジャッジ時間 | 1,070 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
コンパイルメッセージ
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); | ~~~~~^~~~~~~~~~~~~~~~~~~~~
ソースコード
#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; }