题解:
用a[i][j]表示已过时间i,剩余体力为j时方案总数。向上划行距离为:m - j,向下漂流的距离为:i - (m - j),此时距离死亡的距离:D = d + m - j -(i - (m - j))
限制条件为:
1.当D <= 0,则 a[i][j] = 0;
2.当 j = 0,则 a[i][j] = a[i + 1][j] (此为状态转移方程)
当 j > 0,则 a[i][j] = a[i + 1][j] + a[i + 1]j - 1
#include<bits/stdc++.h>
using namespace std;
const int N = 3010, MODE = 1000000009;
int d, t, m, a[N][N];
int main()
{
cin >> d >> t >> m;
a[t][0] = 1;
//当前已过时间为i,剩余体力为j
for(int i = t - 1; i >= 0; i--)
for(int j = 0; j <= m; j++)
{
int D = d + m - j - (i - (m - j));
if (D > 0)
{
if (j - 1 >= 0) a[i][j] = (a[i + 1][j] + a[i + 1][j - 1]) % MODE;
else a[i][j] = a[i + 1][j] % MODE;
}
}
cout << a[0][m];
return 0;
}