# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
91062 | YottaByte | Bank (IZhO14_bank) | C++14 | 1077 ms | 3204 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 <iostream>
using namespace std;
const int N = 22;
#define ll long long
#define ok puts("OK");
int n, m, a[N], mx;
int b[N], dp[1 << N];
string tr(int a, int b)
{
string res = "";
while(a)
{
res += char(a % b + '0');
a /= b;
}
while(res.size() < m)
{
res += '0';
}
return res;
}
void calc(int mask, int p = 0, int c = 0, int last = 0)
{
//cout << tr( mask, 2 ) << " " << c << endl;
//cout << tr( p, 2 ) << " " << c << endl;
//system("pause");
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 ));
int sum = 0;
for(int i = 0; i < m; i++)
if( tomask & ( 1 << i ))
sum += b[i];
if(sum < a[c])
{
//puts("Try");
calc( tomask, p, c, i);
}
else if(sum == a[c])
{
//puts("Gotcha");
dp[tomask] = c + 1;
calc( 0, tomask | p, c + 1, 0);
}
}
}
}
}
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]), mx += b[i];
calc(0);
//cout << cc << endl;
puts("NO");
}
/**
1 5
8
4 2 5 1 3
2 6
9 11
6 8 3 5 4 10
2 6
9 11
6 8 3 5 2 10
5 9
3 7 4 10 9
3 2 9 6 3 9 2 9 1
**/
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... |