# bzoj1044木棍分割

program hehe;
const
q=10007;
var
ans,s,min,max,n,m,i,j,k,l,t:longint;
sum,h:array[0..50000] of longint;
d:array[0..50000,0..1] of integer;

function ok(a:longint):boolean;
var
f,g,cnt:longint;
begin
cnt:=0;
g:=0;
for f:=1 to n do
begin
g:=g+h[f];
if g>a then
begin
inc(cnt);
g:=h[f];
end;
if cnt>m then exit(false);
end;
exit(true);
end;

function ef(l,r:longint):longint;
var
mid:longint;
begin
mid:=(l+r)>>1;
if l=r then exit(l);
if ok(mid) then exit(ef(l,mid))
else exit(ef(mid+1,r));
end;

function mini(a,b:longint):longint;
begin
if a>b then exit(b);
exit(a);
end;

begin
for i:=1 to n do
begin
sum[i]:=h[i]+sum[i-1];
if h[i]>max then max:=h[i];
s:=s+h[i];
end;
min:=ef(max,s);
write(min,' ');
t:=0;
s:=0;
for i:=1 to n do
if sum[i]<=min then
d[i,0]:=1
else break;
for l:=1 to m do
begin
j:=l and 1;
s:=0;
t:=j xor 1;
for i:=1 to n do
begin
s:=s+d[i-1,j xor 1];
k:=t;
while (k<i-1)and(sum[i]-sum[k]>min) do
begin
s:=s-d[k,j xor 1];
inc(t);
inc(k)
end;
d[i,j]:=s mod q;
end;
ans:=(ans+d[n,j])mod q;
end;
writeln(ans);
end.

## 1044: [HAOI2008]木棍分割

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 2111  Solved: 764
[Submit][Status][Discuss]

3 2
1
1
10

10 2

## HINT

n<=50000, 0<=m<=min(n-1,1000).

1<=Li<=1000.

## Source

[Submit][Status][Discuss]
posted @ 2015-06-04 21:57  ChenThree  阅读(107)  评论(1编辑  收藏