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 |
Re:这道题应该可以用DP 呀!可是我还是没有AC,哪位大牛帮忙看一下!In Reply To:这道题应该可以用DP 呀!可是我还是没有AC,哪位大牛帮忙看一下! Posted by:nancyyihao at 2010-01-09 18:12:51 > 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. {思路是先把能组合的方案求出来,定义f[i]为能组合出i的方案的种数, ans=min(sum div f[i]); } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator