結果
問題 |
No.733 分身並列コーディング
|
ユーザー |
![]() |
提出日時 | 2018-09-18 13:46:26 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,082 bytes |
コンパイル時間 | 472 ms |
コンパイル使用メモリ | 72,820 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-18 07:57:50 |
合計ジャッジ時間 | 35,976 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 TLE * 17 |
ソースコード
#include <cstdio> #include <cstring> #include <string> #include <iostream> #include <cmath> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> using namespace std; typedef long long int ll; typedef pair<int, int> P; const int INF=1e7; int main() { int n, T; cin>>T; cin>>n; int t[17]; int sum=0; for(int i=0; i<n; i++){ cin>>t[i]; sum+=t[i]; } if(sum<=T){ cout<<1<<endl; return 0; } int dp[1<<17]; for(int i=1; i<(1<<n); i++){ int s=0; for(int j=0; j<n; j++){ if(i&(1<<j)) s+=t[j]; } if(s<=T) dp[i]=1; else dp[i]=INF; } int p3=1; for(int i=0; i<n-1; i++) p3*=3; for(int i=0; i<p3; i++){ int a=0, a1=0, i1=i, i2=0; while(i1>0){ if(i1%3==1){ a+=(1<<i2); }else if(i1%3==2){ a1+=(1<<i2); } i2++; i1/=3; } if(a==0 || a1==0) continue; dp[a+a1]=min(dp[a+a1], dp[a]+dp[a1]); } int ans=INF; for(int i=1; i<(1<<n)-1; i++){ ans=min(ans, dp[i]+dp[(1<<n)-1-i]); } cout<<ans<<endl; return 0; }