# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
91063 | YottaByte | Bank (IZhO14_bank) | C++14 | 442 ms | 3088 KiB |
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 <stdio.h>
#include <stdlib.h>
using namespace std;
const int N = 22;
int n, m, a[N], b[N];
int dp[1 << N];
void calc(int mask, int p = 0, int c = 0, int last = 0, int sum = 0)
{
if(c == n)
{
puts("YES");
exit(0);
}
for(int i = last; i < m; i++)
{
if(!( mask & ( 1 << i )))
{
if(!( p & ( 1 << i )))
{
int tomask = ( mask | ( 1 << i ));
if(sum + b[i] < a[c])
calc( tomask, p, c, i, sum + b[i]);
else if(sum + b[i] == a[c])
{
dp[tomask] = c + 1;
sum += b[i];
calc( 0, tomask | p, c + 1, 0, 0);
}
else
calc( tomask, p, c, i, sum + b[i]);
}
}
}
}
main()
{
scanf("%d %d", &n, &m);
for(int i = 0; i < n; i++)
scanf("%d", &a[i]);
for(int i = 0; i < m; i++)
scanf("%d", &b[i]);
calc(0);
puts("NO");
}
Compilation message (stderr)
# | 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... |