题目链接: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; }