QuocSensei
bình luận vào 8:39 p.m. 23 Tháng 3, 2024
include <iostream>
using namespace std;
define MAX 100001
int n, m, p, a[10];
bool check[MAX], F[MAX];
int initData(){
int tmp;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
cin >> m;
for (int i = 0; i < m; i++){
cin >> tmp;
check[tmp] = true;
}
cin >> p;
}
void solve(){
for (int i = 0; i < n; i++) if (!check[a[i]]) F[a[i]] = true;
for (int i = 1; i <= p; i++){
if (!check[i])
for (int j = 0; j < n; j++){
if (F[i]) break;
if (i > a[j])
F[i] = F[i - a[j]];
}
}
}
int main(){
initData();
solve();
if (F[p]) cout << "Yes";
else cout << "No";
return 0;
}
Bình luận
include <iostream>
using namespace std;
define MAX 100001
int n, m, p, a[10]; bool check[MAX], F[MAX];
int initData(){ int tmp; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; cin >> m; for (int i = 0; i < m; i++){ cin >> tmp; check[tmp] = true; } cin >> p; }
void solve(){ for (int i = 0; i < n; i++) if (!check[a[i]]) F[a[i]] = true;
}
int main(){ initData(); solve(); if (F[p]) cout << "Yes"; else cout << "No"; return 0; }