forked from hanemin/cs_practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path@4.cs
More file actions
31 lines (31 loc) · 857 Bytes
/
@4.cs
File metadata and controls
31 lines (31 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
namespace _4 {
//1<=n<=20
//-1e8<=a_i<=1e8
//-1e8<=k<=1e8
class Program {
static int n, k;
static int[] a;
static void Solve() {
if (dfs(0, 0))
Console.WriteLine("Yes");
else
Console.WriteLine("False");
}
static bool dfs(int i,int sum) {
if (i == a.Length) return (sum == k);
//not add
if(dfs(i + 1, sum)) return true;
//add
if(dfs(i + 1, sum + a[i])) return true;
//muri
return false;
}
static void Main(string[] args) {
n = int.Parse(Console.ReadLine());
a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
k = int.Parse(Console.ReadLine());
Solve();
}
}
}