이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(int i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define MOD 1000000007
#define maxn 210
#define INF 1e9
int N,M;
int K,A[maxn],B[maxn];
bool dp[20][1010][(1<<10)], done[20][1010][(1<<10)];
ll dpf(int i, int j, int bm){
if (j < 0) return 0;
if (i == N + 1) return 1;
if (done[i][j][bm]) return dp[i][j][bm];
done[i][j][bm] = 1;
if (j == 0) return dp[i][j][bm] = dpf(i+1,A[i+1], bm);
else{
dp[i][j][bm] = 0;
FOR(k,0,M-1) if (!(bm & (1 << k))) dp[i][j][bm] |= dpf(i,j-B[k],bm|(1<<k));
return dp[i][j][bm];
}
}
int32_t main(){
fast;
cin >>N >> M;
FOR(i,1,N) cin >> A[i];
FOR(i,0,M-1) cin >> B[i];
cout << (dpf(1,A[1],0) ? "YES" : "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... |