20160221模拟

T1

题目大意

给定 n,m,d
询问满足以下条件的序列的方案数
对于序列 {A} 满足

  • Ai1<AiAiAi1<=d
  • Ai=n
  • A1[0,d]

题解

AB>=1<=d,dp[i,j]i,Aj
dp[i,j]=dk=1dp[i1,j(mi+1)k]
这样是 O(nmd) 的复杂度
每次转移都是类似的所以我们用个辅助数组 F[i]=dp[i,j 优化转移
复杂度 O(nm)
注意 m n 级别以下才有解,否则ans=0

const
    maxn=300005;
    mmod=1000000007;
var
    dp:array[0..1,0..maxn]of longint;
    f:array[0..maxn]of longint;
    i,j,k:Longint;
    n,m,t,s,a:longint;
begin
    readln(n,m,t); s:=0;
    for i:=1 to m do inc(s,i);
    if s>n then begin writelN(0); halt; end;
    for i:=0 to n do dp[0,i]:=0;
    dp[0,0]:=1;
    a:=0;
    for i:=1 to m do
        begin
            for j:=0 to n do dp[1-a,j]:=0;
            for j:=0 to m-i+1 do f[j]:=0;
            for j:=0 to n do
                begin
                    dp[1-a,j]:=f[j mod (m-i+1)];
                    f[j mod (m-i+1)]:=(f[j mod (m-i+1)]+dp[a,j])mod mmod;
                    if j-(m-i+1)*t>=0 then f[j mod (m-i+1)]:=(f[j mod (m-i+1)]+(mmod-dp[a,j-(m-i+1)*t]))mod mmod;
                end;
            a:=a xor 1;
        end;
    writeln(dp[a,n]);
end.

你可能感兴趣的:(20160221模拟)