本文主要是介绍NEFU 20 穿过街道,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
穿过街道
Problem:20
Time Limit:1000ms
Memory Limit:65536K
Description
一个城市的街道布局如下:从最左下方走到最右上方,每次只能往上或往右走,一共有多少种走法?
Input
输入很多行行数,每行1个数字代表n的值,当n=0时结束(2<=n<=15)
Output
输出对应每行n值的走法.
Sample Input
1 2 10 5 0
Sample Output
2 6 184756 252
Hint
while(scanf("%d",&n)!=EOF&&n!=0) {}
Source
#include <iostream>using namespace std;int main()
{int n;long long a[20][20];for(int i=0;i<20;i++){a[0][i]=1;a[i][0]=1;}for(int j=1;j<20;j++)for(int k=1;k<20;k++)a[j][k]=a[j-1][k]+a[j][k-1];while(cin>>n&&n!=0)cout <<a[n][n]<< endl;return 0;
}
Discuss
这篇关于NEFU 20 穿过街道的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!