solution.cpp 549 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
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
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
long int masks[15] = {9090400, 8499400, 5926800, 8547000, 4958200,
                      4422600, 5751200, 4175600, 6309600,
                      5865200, 6604400, 4635000, 10663400, 8087200, 4554000};

long ans = 1000000000;

void dfs(int n, long h1, long h2)
{
    if (n == 15)
    {
        ans = min(ans, abs(h1 - h2));
        return;
    }
    dfs(n + 1, h1 + masks[n], h2);
    dfs(n + 1, h1, h2 + masks[n]);
}

int main()
{
    dfs(0, 0, 0);
    cout << ans;
}