SGU - 222 Little Rooks
来源:互联网 发布:数控电火花编程实例 编辑:程序博客网 时间:2024/06/05 11:02
Little Rooks
Time Limit: 250MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u
Description
222. Little Rooks
time limit per test: 0.25 sec.
memory limit per test: 65536 KB
memory limit per test: 65536 KB
input: standard
output: standard
output: standard
Inspired by a "Little Bishops" problem, Petya now wants to solve problem for rooks.
A rook is a piece used in the game of chess which is played on a board of square grids. A rook can only move horizontally and vertically from its current position and two rooks attack each other if one is on the path of the other.
Given two numbers n and k, your job is to determine the number of ways one can put k rooks on an n × n chessboard so that no two of them are in attacking positions.
A rook is a piece used in the game of chess which is played on a board of square grids. A rook can only move horizontally and vertically from its current position and two rooks attack each other if one is on the path of the other.
Given two numbers n and k, your job is to determine the number of ways one can put k rooks on an n × n chessboard so that no two of them are in attacking positions.
Input
The input file contains two integers n (1 ≤ n ≤ 10) and k (0 ≤ k ≤ n 2).
Output
Print a line containing the total number of ways one can put the given number of rooks on a chessboard of the given size so that no two of them are in attacking positions.
Sample test(s)
Input
4 4
Output
24
[submit]
[forum]
组合数和排列数,数据不大,结果就是C(n,k)*A(n,k),还要注意k=0时结果为1,k=1时结果为n*n,k>n时为0.
#include<iostream>using namespace std;int main(){long long int n, k;while (cin >> n >> k){long long int sum = 1;long long int ans = 1;if (k > n){cout << 0 << endl; continue;}if (k == 1){cout << n*n << endl; continue;}for (long long int i = n; i > n - k; i--)sum = sum*i;ans = sum;for (long long i = 1; i <= k; i++)ans = ans / i;ans = ans*sum;cout << ans << endl;}}
0 0
- SGU - 222 Little Rooks
- SGU 222 Little Rooks (组合数)
- SGU - 222 - Little Rooks (组合数)
- sgu 222 - Little Rooks 简单的状态压缩DP
- sgu222 Little Rooks
- Little Rooks(简单组合数学)
- SGU 223 Little Kings
- SGU 223 Little Kings
- SGU 223 Little Kings
- SGU 223 Little Kings
- sgu-204 Little Jumper
- sgu-220 Little Bishops
- sgu-223 Little Kings
- SGU 223 Little Kings
- SGU 223. Little Kings
- sgu - 269 - Rooks(大数dp)
- sgu222:Little Rooks(简单组合数学)
- [SGU 223][bsoj2772] little kings
- linux环境python安装setuptools(使用easy_install)的必要条件
- 分页工具类
- TQ2440裸奔三部曲1.1和1.2将3.5屏显示升级为4.3屏
- 设计模式梳理总结(1)
- 【安卓】数据存储之SharedPreferences
- SGU - 222 Little Rooks
- leetcode Remove Duplicates from Sorted Lists
- leetcode remove duplicates from sorted array
- 网络编程(1)--利用socket进行客户端与服务器端的通信
- 栋栋晓10:Javascript学习总结:基础知识2(语句,函数,)
- HDU - 2816 I Love You Too(水)
- 【Android基础篇】AlertDialog自定义setView方法的控件响应方法
- POJ2406 KMP next数组妙用
- HDU 1787 GCD Again 【欧拉函数模板】