이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i<int(b);++i)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define trav(a,c) for(auto a: c)
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
int main(){
cin.sync_with_stdio(false);
ll n,m;
cin>>n>>m;
vi a(n);
vi b(m);
rep(i,0,n) cin>>a[i];
rep(i,0,m) cin>>b[i];
a.push_back(0);
vector<vector<vector<bool> > > dp(n+1,vector<vector<bool> >(1001,vector<bool>(1<<m,true)));//dp[index][left][mask];
for(ll index = n-1;index>=0;index--){
rep(mask,0,(1<<m))
dp[index][0][mask] = dp[index+1][a[index+1]][mask];
rep(left,0,1001){
rep(mask,0,(1<<m)){
dp[index][left][mask] = false;
if(left==0)
dp[index][left][mask] = dp[index+1][a[index+1]][mask];
//cout<<index<<" "<<left<<" ";
rep(i,0,m){
//cout<<((mask&(1<<i))>0);
dp[index][left][mask] = dp[index][left][mask]||((mask&(1<<i))==0&&left>=b[i]&&dp[index][left-b[i]][mask|(1<<i)]);
}
//cout<<": "<<dp[index][left][mask]<<endl;
}
}
}
if(dp[0][a[0]][0]){
cout<<"YES"<<endl;
} else {
cout<<"NO"<<endl;
}
}
# | 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... |