bzoj 1037: [ZJOI2008]生日聚会Party (dp)
dp,但是要顺推容易点
const mm=12345678; var f:array[0..1,0..200,0..20,0..20]of longint; n,m,kk,now,sum,i,j,k1,k2:longint; function max(x,y:longint):longint; begin if x<y then exit(y); exit(x); end; begin readln(n,m,kk); now:=0; f[now][1,1,0]:=1; f[now][0,0,1]:=1; for i:=1 to n+m-1 do begin fillchar(f[1-now],sizeof(f[1-now]),0); for j:=0 to n do begin if (j>i) and (i-j>m) then continue; for k1:=0 to kk do for k2:=0 to kk do if f[now][j,k1,k2]>0 then begin if (k1<kk) and (j<n) then begin inc(f[1-now][j+1,k1+1,max(k2-1,0)],f[now][j,k1,k2]); f[1-now][j+1,k1+1,max(k2-1,0)]:=f[1-now][j+1,k1+1,max(k2-1,0)] mod mm; end; if (k2<kk) and (i-j<m) then begin inc(f[1-now][j,max(k1-1,0),k2+1],f[now][j,k1,k2]); f[1-now][j,max(k1-1,0),k2+1]:=f[1-now][j,max(k1-1,0),k2+1] mod mm; end; end; end; now:=1-now; end; sum:=0; for i:=0 to kk do for j:=0 to kk do sum:=(f[now][n,i,j]+sum) mod mm; writeln(sum); end.
因疲惫而轻易入眠,是对自己一天努力的最好褒奖。 要和泪子一起努力怀抱梦想对抗残酷的现实……