21360_Rooks

2022-5-16 18:19| 发布者: Hocassian| 查看: 44| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505193819300-Problem List-采集的数据-后羿采集器.html

Pro.ID

21360

Title

Rooks

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21360

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Many mathematical problems on chessboard have been studied. The 8-queens problem, may be the most famous, is to place 8 queens on the chessboard so that they do not attack each other. This problem is probably as old as the chess game itself, and thus its origin is not known, but it is known that Gauss studied this problem.

    The same sort of question about rooks can be asked. Two rooks are said to be attacking each other if they are placed in the same row or column of the chessboard. How many ways are there to place 8 non-attacking rooks on a chessboard? The answer is quit easy, and can be soled generally: on an n by n chessboard, the number of ways to place n non-attacking rooks is n! (The two ways of placing on 2-by-2 chessboard are shown in Figure 1.

    Figure 1   two ways of placing on 2-by-2 chessboard

    Since a n-by-n chessboard can also be considered to be a n+1 by n+1 grid, a path can be drawn along the grid line from the upper left comer to the lower right comer by going right or down at each turning.

    A configuration of a chessboard is a placing of rooks with a path that all rooks are below the path (all three configurations of 2-by-2 chessboard are shown in Figure 2).

    Figure 2   all configurations of 2-by-2 chessboard

    Your task is to write a program to calculate the number of configurations in n-by-n chessboard.

    输入

    The input is a sequence of positive integers each in a separate line. The integers are between 1 and 100, inclusive, indicating the size of the chessboard. The end of the input is indicated by a zero.

    输出

    Description

    Many mathematical problems on chessboard have been studied. The 8-queens problem, may be the most famous, is to place 8 queens on the chessboard so that they do not attack each other. This problem is probably as old as the chess game itself, and thus its origin is not known, but it is known that Gauss studied this problem.

    The same sort of question about rooks can be asked. Two rooks are said to be attacking each other if they are placed in the same row or column of the chessboard. How many ways are there to place 8 non-attacking rooks on a chessboard? The answer is quit easy, and can be soled generally: on an n by n chessboard, the number of ways to place n non-attacking rooks is n! (The two ways of placing on 2-by-2 chessboard are shown in Figure 1.

    Figure 1   two ways of placing on 2-by-2 chessboard

    Since a n-by-n chessboard can also be considered to be a n+1 by n+1 grid, a path can be drawn along the grid line from the upper left comer to the lower right comer by going right or down at each turning.

    A configuration of a chessboard is a placing of rooks with a path that all rooks are below the path (all three configurations of 2-by-2 chessboard are shown in Figure 2).

    Figure 2   all configurations of 2-by-2 chessboard

    Your task is to write a program to calculate the number of configurations in n-by-n chessboard.

    Input

    The input is a sequence of positive integers each in a separate line. The integers are between 1 and 100, inclusive, indicating the size of the chessboard. The end of the input is indicated by a zero.

    Output

    The output should be composed of lines each corresponding to an input line except the last zero. An output line includes the number of configurations of the chessboard with the input size. No other characters should be inserted in the output.

    Sample Input

    2
    0

    Sample Output

    3

    Source

    样例输入

    2
    0

    样例输出

    3

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部