Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int c, n, a[30], ans;
- void rec(int v, int cur){
- if(cur > c){
- return;
- }
- if(cur == c){
- ans = 1000;
- return;
- }
- for(int i = v; i <= n; i++){
- if(ans == 1000){
- return;
- }
- rec(i, cur + a[i]);
- }
- }
- int main(){
- //freopen("E.in", "r", stdin);
- //freopen("E.out", "w", stdout);
- scanf("%d %d", &c, &n);
- for(int i = 1; i <= n; i++){
- cin >> a[i];
- }
- for(int i = 1; i <= n; i++){
- rec(i, a[i]);
- if(ans == 1000){
- printf("YES");
- return 0;
- }
- }
- printf("NO");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement