"Huawei OJ" "059-201301-java-topic Level 2-3"

Source: Internet
Author: User

"Huawei OJ" "Algorithm Total chapter" "Huawei OJ" "059-201301-java-topic Level 2-3" "Project Download" topic description
请编写一个函数(允许增加子函数),计算n x m的棋盘格子(n为横向的格子数,m为竖向的格子数)沿着各自边缘线从左上角走到右下角,总共有多少种走法,要求不能走回头路,即:只能往右和往下走,不能往左和往上走。
Enter a description
输入两个正整数
Output description
返回结果
Input example
22
Output example
6
Algorithm implementation
ImportJava.util.Arrays;ImportJava.util.Scanner;/** * Author: Wang Junshu * date:2015-12-25 16:31 * All rights Reserved!!! */ Public  class Main {     Public Static void Main(string[] args) {Scanner Scanner =NewScanner (system.in);//Scanner Scanner = new Scanner (Main.class.getClassLoader (). getResourceAsStream ("Data.txt"));         while(Scanner.hasnext ()) {intn = scanner.nextint ();intm = Scanner.nextint ();        System.out.println (count (n, m));    } scanner.close (); }Private Static int Count(intNintm) {int[] Path =New int[n +1][m +1]; for(inti =0; I < path[0].length; i++) {path[0][i] =1; } for(inti =0; i < path.length; i++) {path[i][0] =1; } for(inti =1; i < path.length; i++) { for(intj =1; J < path[0].length; J + +) {Path[i][j] = path[i-1][J] + path[i][j-1]; }        }returnPATH[N][M]; }}

"Huawei OJ" "059-201301-java-topic Level 2-3"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.