其实也不用非要压去一维

才到30二维完全莫得问题啊

设f[i][j]表示第i次传球传到第j个人的最大次数

f[i][j]=max(f[i][j],f[i-1][j-1]+f[i-1][j+1])

注意他是个环所以还要判断边界情况

#include <cstdio>
#include <iostream>
using namespace std;
const int N = 50;
int n, m, f[N][N];
int read() {
    int s = 0, w = 1;
    char ch = getchar();
    while(!isdigit(ch)) {if(ch == '-') w = -1; ch = getchar();}
    while(isdigit(ch)) {s = s * 10 + ch - '0'; ch = getchar();}
    return s * w;
}
int main() {
    n = read(), m = read();
    f[0][1] = 1;
    for(int i = 1; i <= m; i++)
        for(int j = 1; j <= n; j++)
            if(j == 1) f[i][j] = max(f[i][j], f[i - 1][n] + f[i - 1][j + 1]);
            else if(j == n) f[i][j] = max(f[i][j], f[i - 1][j - 1] + f[i - 1][1]);
            else f[i][j] = max(f[i][j], f[i - 1][j - 1] + f[i - 1][j + 1]);
    printf("%d\n", f[m][1]);
    return 0;
} 

谢谢收看, 祝身体健康!

01-19 16:06