# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
199390 | 2020-02-01T07:25:21 Z | kshitij_sodani | Detecting Molecules (IOI16_molecules) | C++17 | 0 ms | 0 KB |
#include <iostream> #include <bits/stdc++.h> #include "molecules.h" using namespace std; typedef long long int llo ; #define mp make_pair #define pb push_back #define a first #define b second vector<llo> find_subset(llo l,llo u,vector<llo> w){ llo dp[1001]; memset(dp,0,sizeof(dp)); dp[0]=1; for(llo j=0;j<w.size();j++){ for(llo i=1001;i>=w[j];i--){ if(dp[i-w[j]]!=0 and dp[i]==0){ dp[i]=j+1; } } } llo ind=-1; for(llo i=l;i<u+1;i++){ if(dp[i]>0){ ind=i; break; } } //cout<<ind<<endl; //cout<<w[dp[15]]<<endl; vector<llo> ans; if(ind==-1){ return ans; } while(ind>0){ ans.pb(dp[ind]); ind-=w[dp[ind]-1]; } return ans; } /* int main(){ vector<llo> ss=find_subset(15,17,{6,8,8,7}); for(int i=0;i<ss.size();i++){ cout<<ss[i]<<" "; } cout<<endl; return 0; }*/