Submission #496018

#TimeUsernameProblemLanguageResultExecution timeMemory
496018DeepessonBank (IZhO14_bank)C++17
100 / 100
163 ms14936 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...