|
|
back to boardAC DFS Posted by xyqxyq 13 May 2019 18:17 #include <iostream> #include <cstdio> #include <cmath> using namespace std; int w[25]; int n; int ans = 1<<30; void DFS(int cnt, int pileone, int piletwo) { if (cnt == n) { if (ans > (int)abs(pileone - piletwo)) { ans = (int)abs(pileone - piletwo); } return ; }
DFS(cnt + 1, pileone + w[cnt], piletwo); DFS(cnt + 1, pileone, piletwo + w[cnt]); } int main() { scanf("%d", &n); for (int i=0; i<n; i++) { scanf("%d", &w[i]); }
DFS(0, 0, 0); printf("%d\n", ans); return 0; } /* 20 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 */ |
|
|