dp加高精90分求助大佬!!!

P1255 数楼梯

yangdaobovip @ 2023-04-16 19:19:43

#include <iostream>
#include <cstring>
using namespace std;
const int MAXN = 5005;
int dp[MAXN][5005];
int main() {
    memset(dp, 0, sizeof(dp));
    int n;
    cin >> n;

    dp[1][0] = 1;
    dp[2][0] = 2;
    if(n == 1) {
        cout << 1 << endl;
        return 0;
    }
    if(n == 2) {
        cout << 2 << endl;
        return 0;
    }
    for(int i = 3; i <= n; i++) {
        for(int j = 0; j < 1005; j++) {
            dp[i][j] += dp[i - 1][j] + dp[i - 2][j];
            if(dp[i][j] >= 10) {
                dp[i][j + 1] += dp[i][j] / 10;
                dp[i][j] %= 10;
            }
        }
    }
    int k = 1004;
    while(dp[n][k] == 0) k--;
    for(int i = k; i >= 0; i--) {
        cout << dp[n][i];
    }
    return 0;
}

by dgdyrkst @ 2023-04-16 19:51:42

高精位数少了

循环改到3005就可以


|