1 条题解
-
0
C :
int n,m; int s(int x) { if(x<1) return x+n; if(x>n) return x-n; return x; } int main() { int a[31][31],i,j; memset(a,0,sizeof(a)); scanf("%d%d",&n,&m); a[1][2]=a[1][n]=1; for (i=2;i<=m;i++) for (j=1;j<=n;j++) a[i][j]=a[i-1][s(j-1)]+a[i-1][s(j+1)]; printf("%d\n",a[m][1]); return 0; }
C++ :
#include<stdio.h> #include<iostream> using namespace std; int m,n; int pd(int x) { if(x<1)return x+n; if(x>n)return x-n; return x; } int main() { int f[31][31]={0},i,j; cin>>n>>m; f[1][2]=f[1][n]=1; for(i=2;i<=m;i++) { for(j=1;j<=n;j++) { f[i][j]=f[i-1][pd(j-1)]+f[i-1][pd(j+1)]; } } cout<<f[m][1]; return 0; }
Pascal :
var n,m,i,j:longint; f:array[1..33,0..33]of longint; begin //assign(input,'ball.in'); reset(input); //assign(output,'ball.out'); rewrite(output); readln(n,m); f[1,0]:=1; for i:=1 to m do for j:=1 to n do if j=1 then f[j,i]:=f[n,i-1]+f[2,i-1] else if j=n then f[j,i]:=f[1,i-1]+f[n-1,i-1] else f[j,i]:=f[j+1,i-1]+f[j-1,i-1]; writeln(f[1,m]); //close(input); //close(output); end.
- 1
信息
- ID
- 262
- 时间
- 1000ms
- 内存
- 50MiB
- 难度
- 10
- 标签
- 递交数
- 2
- 已通过
- 1
- 上传者