Submission #658857

#TimeUsernameProblemLanguageResultExecution timeMemory
658857a_aguiloBank (IZhO14_bank)C++14
71 / 100
1095 ms86388 KiB
#include<bits/stdc++.h> using namespace std; int main(){ int n, m; cin >> n >> m; int salaries[n]; int banknotes[m]; for(int i = 0; i < n; ++i) cin >> salaries[i]; for(int i = 0; i < m; ++i) cin >> banknotes[i]; int DP[1<<m][n+1]; memset(DP, -1, sizeof(DP)); DP[0][0] = 0; for(int mask = 1; mask < (1 << m); ++mask){ for(int note = 0; note < m; ++note){ if(mask&(1<<note)){ DP[mask][0] = DP[mask^(1<<note)][0] + banknotes[note]; } } //cout << DP[mask][0] << endl; } bool IsPossible = false; for(int person = 1; person <= n; ++person){ for(int mask = 1; mask < (1<<m); ++mask){ if(DP[mask][person-1] == salaries[person-1]) DP[mask][person] = 0; for(int note = 0; note < m; ++note){ if(mask&(1<<note)){ if(DP[mask^(1 << note)][person] != -1){ DP[mask][person] = DP[mask^(1<<note)][person]+banknotes[note]; } } } if((person == n) and (DP[mask][person] != -1)) IsPossible = true; } } if(IsPossible) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...