#include <stdio.h>
long long path[60][60];
long long solve(int a, int b) {
if (path[a][b]) return path[a][b];
if (b < a) return 0;
if (b == a + 1) return 1;
if (b == a + 2) return 2;
return (path[a][b] = solve(a, b - 1) + solve(a, b - 2));
}
int
main(int argc, char **argv) {
int ncase;
int a, b;
int i, j;
for (i = 1; i <= 50; ++ i)
path[i][i] = 1, path[i][i+1] = 1, path[i][i+2] = 2;
scanf("%d", &ncase);
while (ncase--) {
scanf("%d%d", &a, &b);
printf("%lld\n", solve(a, b));
}
return 0;
}
注意要把算过的结果存下来,以前算过的就不要再算直接调用。
HDU 2044 一只小蜜蜂...
最新推荐文章于 2022-02-07 16:31:01 发布