AGC013D Pilling Up 動態規劃

2022-05-25 15:00:17 字數 2029 閱讀 4388

首先我們很容易想到乙個dp。 讓f

[i][

j]' role="presentation" style="position: relative">f[i

][j]

f[i]

[j]表示

i' role="presentation" style="position: relative">i

i次操作後有

j' role="presentation" style="position: relative">j

j個紅球的拿球的方案數。

易得轉移 若j

>

0' role="presentation" style="position: relative">j

>0j

>0,

f[i]

[j]−

>f[

i+1]

[j−1

]' role="presentation" style="position: relative">f[i

][j]

−>f[

i+1]

[j−1

]f[i

][j]

−>f[

i+1]

[j−1

] f[

i][j

]−>f[

i+1]

[j]' role="presentation" style="position: relative">f[i

][j]

−>f[

i+1]

[j]f

[i][

j]−>f[

i+1]

[j]

若j<

n' role="presentation" style="position: relative">j

f[i]

[j]−

>f[

i+1]

[j+1

]' role="presentation" style="position: relative">f[i

][j]

−>f[

i+1]

[j+1

]f[i

][j]

−>f[

i+1]

[j+1

] f[

i][j

]−>f[

i+1]

[j]' role="presentation" style="position: relative">f[i

][j]

−>f[

i+1]

[j]f

[i][

j]−>f[

i+1]

[j]

但是這樣子我們會算重複,因為詢問的是顏色序列的方案數,不是拿球的方案數。

觀察發現答案為共

n' role="presentation" style="position: relative">n

n個球的答案減去共n−

1' role="presentation" style="position: relative">n−1

n−1個球的答案,於是好像沒了?

怎麼證?我也不知道qaq

#include

#include

#include

#include

using

namespace

std;

const

int n=3005,mod=1000000007;

int n,m,f[n][n*2];

int calc(int n)

for(int i=0;ifor(int j=0;j<=n;j++)

if(j1][j+1]=(f[i+1][j+1]+f[i][j])%mod;

f[i+1][j]=(f[i+1][j]+f[i][j])%mod;}}

}int ans=0;

for(int i=0;i<=n;i++)

return ans;

}int main()