이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int n, m;
vector<int>people, banknotes;
vector<vector<vector<short>>>table;
short rec(int indx, int mask, int cur_people){
if(indx == n)return 1;
if(cur_people < 0)return 0;
if(cur_people == 0){
indx++;
if(indx == n)return 1;
cur_people = people[indx];
}
bool res = 0;
if(table[indx][mask][cur_people] != -1)return table[indx][mask][cur_people];
for(int i = 0;i < m;++i){
if(mask & (1 << i)){
res = res | rec(indx, mask ^ (1 << i), cur_people - banknotes[i]);
}
}
return table[indx][mask][cur_people] = res;
}
int main()
{
cin >> n >> m;
people.resize(n);
banknotes.resize(m);
table.assign(n, vector<vector<short>>((1 << m), vector<short>(1001, -1)));
for(int i = 0;i < n;++i)cin >> people[i];
for(int i = 0;i < m;++i)cin >> banknotes[i];
if(rec(0, (1 << m) - 1, people[0])){
cout << "YES";
}
else{
cout << "NO";
}
}
# | 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... |