이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#pragma optimize ("-Ofast")
//#pragma comment (linker, "-STACK 99999999")
#define ld long double
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
//#define int long long
using namespace std;
const int maxn = 25;
int N;
int worker[maxn];
bool f(int nm, vector <int> a)
{
if (nm == N)
{
return true;
}
int n = int(a.size());
int sum = worker[nm];
bool flag = false;
for(int i = 0; i < (1 << n) && !flag; i++)
{
int val = 0;
for(int j = 0; j < n; j++)
{
if ((i & (1 << j)) > 0)
{
val += a[j];
}
}
if (sum == val)
{
vector <int> vc;
for(int j = 0; j < n; j++)
{
if ((i & (1 << j)) > 0)
{
vc.pb(a[j]);
}
}
flag = f(nm + 1, vc);
}
}
return flag;
}
int32_t main()
{
#ifdef LOCAL
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#else
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int m;
cin >> N >> m;
for(int i = 0; i < N; i++)
{
cin >> worker[i];
}
vector <int> a(m);
for(int i = 0; i < m; i++)
{
cin >> a[i];
}
if (f(0, a))
{
cout << "YES";
}
else
{
cout << "NO";
}
return 0;
}
# | 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... |