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 <bits/stdc++.h>
#define MAXN 21
#define MAXP 1100000
bool existe[MAXN][MAXP];
bool conseguiu=false;
long long precisa[MAXN];
int N,M;
long long valor[MAXN];
long long pessoa[MAXN];
void dp(int pos,long long pente,long long usados,long long total){
if(conseguiu)return;
long long atual = total-usados;
if(pos==N){
conseguiu=true;
return;
}
if(atual==pessoa[pos]){
dp(pos+1,pente,total,total);
return;
}
if(atual>pessoa[pos])return;
if(existe[pos][pente])return;
existe[pos][pente]=true;
for(int i=0;i!=M;++i){
if(!(pente&(1<<i))){
dp(pos,pente|(1<<i),usados,total+valor[i]);
}
}
}
int main()
{
std::cin>>N>>M;
for(int i=0;i!=N;++i){
std::cin>>pessoa[i];
}
for(int i=0;i!=M;++i){
std::cin>>valor[i];
}
dp(0,0,0,0);
if(conseguiu){
std::cout<<"YES\n";
}else std::cout<<"NO\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |