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

Why my Programme Crash?
Posted by China_ZZX 29 Jul 2010 10:57
using System;
namespace acm1005
{
    class Program
    {
        public static int[] w=new int[21];
        public static bool[] f;
        public static int DP_StonePile(int n)
        {
            int total=0;
            for(int i=1;i<=n;i++) total+=w[i];
            int avg=total/2;
            f=new bool[total];
            f[0]=true;
            int max=0;
            for(int j=1;j<=n;j++)
                for(int i=avg-w[j];i>=0;i--)
                {
                    if(f[i]==true)
                    {
                        f[i+w[j]]=true;
                        if(i+w[j]>max) max=i+w[j];
                    }
                }
            return total-2*max;
        }
        public static void Main(string[] args)
        {
            int n=Int32.Parse(Console.ReadLine());
            for(int i=1;i<=n;i++)
                w[i]=Int32.Parse(Console.ReadLine());
            Console.WriteLine(DP_StonePile(n));
            //Console.Write("Press any key to continue . . . ");
            //Console.ReadKey(true);
        }
    }
}
Re: Why my Programme Crash?
Posted by Nguyen Dang Duy 13 Jan 2012 10:55
Mine too @.@
Re: Why my Programme Crash?
Posted by llf 24 Jan 2012 13:08
OH I got Crash on test #4 ,too`~~~
Nguyen Dang Duy wrote 13 January 2012 10:55
Mine too @.@