60分,求助。我是直接在数楼梯那一题的基础上改的
查看原帖
60分,求助。我是直接在数楼梯那一题的基础上改的
1494443
wdmzjhyk楼主2024/11/21 18:42
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include <string.h>
int s[5001][5001] = { 0 };
int b;
int main()
{
	s[0][1] = 0;
	s[1][1] = 1;
	s[2][1] = 1;
	int m,n;
	scanf("%d%d",&m,&n);
	int cha = n - m;
	for (int i = 3; i <= n; i++)
	{
		for (int j = 1; j < 5000; j++)
		{
			s[i][j] += s[i - 1][j] + s[i - 2][j];
			if (s[i][j] > 9)
			{
				s[i][j] -= 10;
				s[i][j + 1]++;
			}
		}
	}
	for (int k = 5000; k > 0; k--)
	{
		if (b == 0 && s[n][k] == 0) continue;
		b = 1;
		printf("%d", s[n][k]);
	}
	return 0;
}
2024/11/21 18:42
加载中...