题目:
链接:https://www.luogu.com.cn/problem/P8725
思路:dp[i][j]表示第i个时刻还有多少体力
之前的错误思路:dp[i][j][k]表示第i个时刻,在j位置,有k个体力。
但是注意:这三个变量并不是相互独立!!
动规的一个取变量原则应该是相互独立确定某个状态。
剩下k体力和i时刻可以推出位置!!
site = d + (m - j) - (i - (m - j))
还有一个注意点就在于记得清空now,不能被-2前面的影响了。
最后答案就是dp[now][0]也即没有体力的时刻。
代码:
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<sstream>
#include<string>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<map>
#include<queue>
#include<limits.h>
#include<climits>
#include<fstream>
#include<stack>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
ll dp[2][5000];
int main()
{
int d, t, m; cin >> d >> t >> m;
dp[0][m] = 1;
int now = 0;
for (int i = 1; i <= t; i++)
{
now = 1 - now;
memset(dp[now], 0, sizeof(dp[now]));//important
for (int j = 0; j <= m; j++)
{
int lenth = d + (m - j) - (i - (m - j));
if (lenth> 0)
{
dp[now][j] = (dp[1 - now][j] + dp[1 - now][j + 1])%mod;
}
}
}
cout << dp[now][0];
return 0;
}
标签:now,int,ll,P8725,蓝桥,AB3,include,dp
From: https://www.cnblogs.com/zzzsacmblog/p/18129911