結果

問題 No.357 品物の並び替え (Middle)
ユーザー horiesiniti
提出日時 2016-07-21 09:47:32
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 1,156 bytes
コンパイル時間 1,083 ms
コンパイル使用メモリ 72,272 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-15 20:14:45
合計ジャッジ時間 1,654 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:26:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   26 |         scanf("%d %d",&n,&m);
      |         ~~~~~^~~~~~~~~~~~~~~
main.cpp:30:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |                 scanf("%d %d %d",&a,&b,&c);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <stdio.h>
#include <map>
#include <string.h>
#include <algorithm>
int con[15][15];
int n;
int f(int perm,int p){
int res=0;
for(int i=0;i<n;i++){
int b=1<<i;
if((perm&b)==0)continue;
if(con[i][p]!=-1){
res+=con[i][p];
}
}
return res;
}
int main() {
// your code goes here
int m;
std::map<int,int> dp;
scanf("%d %d",&n,&m);
memset(con,-1,sizeof(con));
for(int i=0;i<m;i++){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
con[a][b]=c;
}
for(int i=0;i<n;i++){
dp[1<<i]=0;
}
for(int i=1;i<n;i++){
std::map<int,int> next;
std::map<int,int>::iterator it;
for(it=dp.begin();it!=dp.end();it++){
int perm=(*it).first;
int score=(*it).second;
for(int j=0;j<n;j++){
int bit=1<<j;
if((perm&bit)!=0)continue;
int perm2=perm|bit;
int score2=score+f(perm,j);
//printf("(%d %d %d)",perm,perm2,score2);
if(next.find(perm2)==next.end()){
next[perm2]=score2;
}else if(next[perm2]<score2){
next[perm2]=score2;
}
}
}
dp.clear();
dp.insert(next.begin(),next.end());
}
std::map<int,int>::iterator it=dp.begin();
printf("%d\n",(*it).second);
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0