璟雯院

珺璟如晔,雯华若锦

用户工具

站点工具


icpc:problems:luogup8395
problems
名称Good Fours and Good Fives
题目编号P8395
题目链接luogu.com.cn/…
来源Luogu
算法分类动态规划, 线性动态规划
难易程度容易

Good Fours and Good Fives

想法

直接计算会重复,分开计算会避免4和5重叠的情况。先枚举4能组合出的数,再枚举5能组合出的数。

代码实现

#include<cstdio>
 
const int N = 1e6+10;
int f[N];
int main() {
	int n;
	scanf("%d", &n);
	f[0] = 1;
	for(int i=1; i<=n; i++) 
		if(i-4 >= 0)
			f[i] += f[i-4];
	for(int i=1; i<=n; i++)
		if(i-5 >= 0)
			f[i] += f[i-5];
	printf("%d", f[n]);
	return 0;
}
/app/www/public/data/pages/icpc/problems/luogup8395.txt · 最后更改: 2024/03/20 16:17 由 温婕莺