Last active
August 29, 2015 14:22
-
-
Save yamaguchi1024/50b7f5f5183dcc2d6edf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<cstdio> | |
#include<iostream> | |
using namespace std; | |
bool dfs(int, int); | |
void solve(int); | |
int a[50]; | |
int n, k; | |
int main(){ | |
scanf("%d\n", &n); | |
for( int i = 0; i <= n-1; i++){ | |
scanf("%d", &a[i]); | |
} | |
scanf("%d\n", &k); | |
dfs(0, 0); | |
if(dfs(0, 0)) printf("Yeah!\n"); | |
else printf("No\n"); | |
return 0; | |
} | |
bool dfs(int e, int sum){ | |
if(e1 == n) return sum == k; | |
if(dfs(e + 1, sum)) return true; | |
if(dfs(e + 1, sum + a[e])) return true; | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment