Problem P11. [算法课动态规划]爬楼梯
作者:互联网
动态规划当前状态和前一状态相关。到
m
阶楼梯的方法等于到m-1
和m-2
的方法相加
#include<iostream>
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
int n;
int cnt[25];
int main()
{
scanf("%d", &n);
cnt[0] = 1;
cnt[1] = 1;
for (int i = 2; i <= n; i++){
cnt[i] = cnt[i-1]+cnt[i-2];
}
printf("%d", cnt[n]);
return 0;
}
标签:cnt,动态,爬楼梯,int,scanf,namespace,P11,Problem,include 来源: https://www.cnblogs.com/understanding-friends/p/16669080.html