# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
788386 | Bula | Detecting Molecules (IOI16_molecules) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
//#define int ll
const ll mod=1e9+7;
vector<int> find_subset(int l,int u,vector<int> w){
int n=(int)w.size();
vector<int> v(n+1);
for(int i=1;i<=n;i++) v[i]=w[i-1];
int dp[n+1][u+1];
for(int i=0;i<=n;i++){
for(int j=1;j<=u;j++){
dp[i][j]=0;
}
}
vector<int> ans;
for(int i=1;i<=n;i++){
dp[i][v[i]]=2;
for(int j=u;j>=1;j--){
if(dp[i-1][j]>0 && dp[i][j]==0) dp[i][j]=1
if(j>v[i]) dp[i][j]=max(dp[i][j],dp[i-1][j-v[i]]);
}
}
int sum=0;
for(int i=l;i<=u;i++){
if(dp[n][i]>0){
sum=i;
break;
}
}
int i=n;
while(sum!=0){
if(dp[i][sum]==2){
sum-=v[i];
ans.pb(i-1);
i--;
}else{
i--;
}
}
return ans;
}