ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1005. Stone Pile

Brute Force Search
Posted by Zhihua Lai 16 Oct 2006 22:10
Just use brute forch search,
cannot dp,
Re: Brute Force Search
Posted by @lexx-B/\/\STU 4 Nov 2006 15:45
Yes
int main()
{
    int N;
    int W[20];
    int t = 0;
    int r = 1 << 30;

    cin >> N;

    for(int i = 0; i < N; i++) cin >> W[i];

    for(int i = 0; i < (1<<N); i++)
    {
        for(int j = 0; j < N; j++)
            t += ((1<<j)&i)?W[j]:-W[j];
        r = min(r,abs(t));
        t = 0;
    }

    cout << r;

    return 0;
}