标签:dp
3 2 4 2 3 2 3 2
4 0Hint第一组测试中有以下四种走法: 2->1->2->1->2 2->1->2->3->2 2->3->2->1->2 2->3->2->3->2
#include <map> #include <set> #include <list> #include <stack> #include <queue> #include <vector> #include <cmath> #include <cstdlib> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int dp[105][105]; int main() { int n, p, m, t; while (~scanf("%d%d%d%d", &n, &p, &m, &t)) { memset (dp, 0, sizeof(dp)); int l = p - 1, r = p + 1; dp[p][0] = 1; for (int i = 1; i <= m; i++) { for (int j = (l >= 1 ? l : 1); j <= (r <= n ? r : n); j++) { if (j > 1) { dp[j][i] += dp[j - 1][i - 1]; } if (j < n) { dp[j][i] += dp[j + 1][i - 1]; } l--; r++; } } printf("%d\n", dp[t][m]); } return 0; }
标签:dp
原文地址:http://blog.csdn.net/guard_mine/article/details/41144667