标签:nyoj325
5 5 8 13 27 14
3
#include <stdio.h> #define abs(x) (x) > 0 ? (x) : -(x) int n, arr[22], sum, min, temp, t; void DFS(int pos){ if((t = abs(sum - 2 * temp)) < min) min = t; if(pos == n) return; for(int i = pos; i < n; ++i){ temp += arr[i]; DFS(i + 1); temp -= arr[i]; } } int main(){ while(scanf("%d", &n) == 1){ temp = sum = 0; min = 200002; for(int i = 0; i < n; ++i){ scanf("%d", arr + i); sum += arr[i]; } DFS(0); printf("%d\n", min); } return 0; }
NYOJ325 zb的生日 【DFS】,布布扣,bubuko.com
标签:nyoj325
原文地址:http://blog.csdn.net/chang_mu/article/details/30268161