Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
这道题应该可以用DP 呀!可是我还是没有AC,哪位大牛帮忙看一下!program p_1011; const maxn=10000; var f,a:array[0..maxn] of longint; n,sum:longint; procedure main; var i,j,ans:longint; begin sum:=0; for i:=1 to n do begin read(a[i]); inc(sum,a[i]); end; fillchar(f,sizeof(f),0); f[0]:=1; for i:=n downto 1 do for j:=sum downto a[i] do inc(f[j],f[j-a[i]]); for i:=1 to sum do write(f[i],' '); writeln; ans:=maxlongint; for j:=1 to sum do if f[j]<>0 then if sum mod f[j]=0 then if sum div f[j]<ans then ans:=sum div f[j]; writeln(ans); end; begin assign(input,'p_1011.in'); reset(input); assign(output,'p_1011.out'); rewrite(output); readln(n); while n<>0 do begin main;readln(n);end; close(input); close(output); end. Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator