http://acm.dlut.edu.cn/problem.php?id=1309
总是觉得这种dp好奇怪!
AC代码:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX = 35;
int dp[MAX][MAX];
int main(){
int n,m;
while(cin >> n >> m){
memset(dp, 0, sizeof(dp));
dp[1][0] = 1;
for(int i=1; i<=m; i++){
dp[1][i] = dp[n][i-1] + dp[2][i-1];
dp[n][i] = dp[1][i-1] + dp[n-1][i-1];
for(int j=2; j<n; j++)
dp[j][i] = dp[j-1][i-1] + dp[j+1][i-1];
}
cout << dp[1][m] << endl;
}
//system("pause");
return 0;
}
本文分享了一道一维动态规划题目AC代码实现过程。通过分析递推公式,使用C++实现了状态转移方程,解决了特定类型的问题。该代码利用双重循环更新dp数组,最终输出目标状态。
241

被折叠的 条评论
为什么被折叠?



