1-养兔子
#include <stdio.h>
#include <stdlib.h>
long long a[111] = {1, 1, 2, 3, 5};
int main()
{
int n;
scanf("%d", &n);
int i;
for(i = 2; i <= n; i ++)
{
a[i] = a[i - 1] + a[i - 2];
}
printf("%lld\n", a[n]);
return 0;
}
2 - 母牛的故事
#include <stdio.h>
#include <stdlib.h>
long long a[111] = {0, 1, 2, 3, 4};
int main()
{
int n;
scanf("%d", &n);
int i;
for(i = 4; i <= n; i ++)
{
a[i] = a[i - 1] + a[i - 3];
}
printf("%lld\n", a[n]);
return 0;
}
马拦过河卒
#include <stdio.h>
#include <stdlib.h>
#define N 1111
int a[N][N];
int f[N][N];
int main()
{
int n, m, b, c, i, j;
scanf("%d %d %d %d", &n, &m, &b, &c);
n ++;
m ++;
b ++;
c ++;
for(i = 0; i <= n; i ++)
{
for(j = 0; j <= m; j ++)
{
a[i][j] = 1;
}
}
a[b][c] = 0;
a[b - 1][c - 2] = 0;
a[b - 2][c - 1] = 0;
a[b - 2][c + 1] = 0;
a[b - 1][c + 2] = 0;
a[b + 1][c + 2] = 0;
a[b + 2][c + 1] = 0;
a[b + 2][c - 1] = 0;
a[b + 1][c - 2] = 0;
for(i = 0; i <= n; i ++)
{
for(j = 0; j <= m; j ++)
{
f[i][j] = 0;
}
}
f[1][1] = 1;
for(i = 1; i <= n; i ++)
{
for(j = 1; j <= m; j ++)
{
if(i == 1 && j == 1) continue;
if(a[i][j] == 1)
f[i][j] = f[i - 1][j] + f[i][j - 1];
}
}
printf("%d\n", f[n][m]);
return 0;
}
7-3 骨牌铺方格 (20 分)
#include <stdio.h>
#include <stdlib.h>
long long a[111] = {0, 1, 2, 3, 5};
int main()
{
int n;
scanf("%d", &n);
int i;
for(i = 4; i <= n; i ++)
{
a[i] = a[i - 1] + a[i - 2];
}
printf("%lld\n", a[n]);
return 0;
}
7-4 三国佚事——巴蜀之危 (20 分)
#include <stdio.h>
#include <stdlib.h>
long long a[1111] = {0, 0, 1};
int main()
{
int n;
scanf("%d", &n);
int i;
for(i = 3; i <= n; i ++)
{
a[i] = (i - 1)*(a[i - 1] + a[i - 2]);
}
printf("%lld\n", a[n]);
return 0;
}
7-5 蟠桃记 (20 分)
#include <stdio.h>
#include <stdlib.h>
long long a[1111] = {0, 1};
int main()
{
int n;
scanf("%d", &n);
int i;
for(i = 2; i <= n; i ++)
{
a[i] = (a[i - 1] + 1)*2;
}
printf("%lld\n", a[n]);
return 0;
}
7-6 C语言实验——拍皮球 (20 分)
#include <stdio.h>
#include <stdlib.h>
int main()
{
float n, m;
scanf("%f %f", &n, &m);
int i;
float s = n, h = n;
for(i = 2; i <= m; i ++)
{
n *= 0.5;
s += 2 * n;
}
for(i = 1; i <= m; i ++)
{
h *= 0.5;
}
printf("%.2f %.2f\n", s, h);
return 0;
}