# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1097722 | 2024-10-08T04:29:03 Z | Newtonabc | Detecting Molecules (IOI16_molecules) | C++14 | 0 ms | 0 KB |
#include "molecules.h" #include<bits/stdc++.h> using namespace std; const int N=1e5+10; bool dp[N]; int bk[N]; int n; vector<int> find_subset(int l, int u, vector<int> w) { n=w.size(); vector<int> ans; dp[0]=true; for(int i=0;i<n;i++){ for(int j=u;j>=0;j--){ if(j-w[i]>=0){ if(!dp[j] && dp[j-w[i]]){ dp[j]|=dp[j-w[i]]; bk[j]=i; } } } } for(int i=l;i<=u;i++){ if(dp[i]){ int tmp=i; //cout<<i <<"\n\n\n\n"; while(1){ if(tmp==0) break; ans.push_back(bk[tmp]); tmp-=w[bk[tmp]a]; } break; } } /*for(int i=0;i<ans.size();i++) cout<<ans[i] <<" "; cout<<"\n\n\n";*/ return ans; }