【算法1-4】递推与递归【持续更新中】
作者:互联网
P1255 数楼梯
题目链接:P1255 数楼梯 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
#include <iostream>
using namespace std;
int a[5010][5010];
int main() {
a[0][0] = 1;
a[1][0] = 1;
int n;
cin >> n;
if (n == 0) {
cout << 0;
} else {
for (int i = 2; i <= n; i++) {
//a[i]=a[i-1]+a[i-2]; 高精加
int x, y;
for (int j = 0; j < 1500; j++) {
a[i][j] += a[i - 1][j] + a[i - 2][j];
int index = j;
while (a[i][index] >= 10) {
a[i][index + 1] += a[i][index] / 10;
a[i][index] %= 10;
index++;
}
}
}
bool flag = 0;
for (int i = 1500; i >= 0; i--) {
if (a[n][i] != 0) {
flag = 1;
}
if (flag == 1) {
cout << a[n][i];
}
}
}
return 0;
}
标签:5010,index,P1255,递归,10,int,flag,算法,递推 来源: https://blog.csdn.net/weixin_53199925/article/details/121464431